From 346722b2d05461eaf8e1631530af2cfb4e7fdee4 Mon Sep 17 00:00:00 2001 From: Alexis Date: Wed, 15 Sep 2021 15:41:47 +0930 Subject: [PATCH] fix: ensure we're only reconnecting one connection --- app/mothership/index.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/app/mothership/index.ts b/app/mothership/index.ts index 5cc603a18..28e11720f 100644 --- a/app/mothership/index.ts +++ b/app/mothership/index.ts @@ -187,9 +187,14 @@ export const startRelay = () => { // Retry in 30s setTimeout(() => { - log.debug(`☁️ RELAY:${message ?? 'API_KEY_IN_USE'}:RECONNECTING`); + // Another process has already kicked this off + if (isRelayConnecting) { + return; + } // Restart relay connection + isRelayConnecting = true; + log.debug(`☁️ RELAY:${message ?? 'API_KEY_IN_USE'}:RECONNECTING:NOW`); sockets.relay?.start(); }, 30_000); @@ -200,9 +205,14 @@ export const startRelay = () => { // Retry in 60s setTimeout(() => { - log.debug(`☁️ RELAY:${message ?? 'INTERNAL_SERVER_ERROR'}:RECONNECTING`); + // Another process has already kicked this off + if (isRelayConnecting) { + return; + } // Restart relay connection + isRelayConnecting = true; + log.debug(`☁️ RELAY:${message ?? 'INTERNAL_SERVER_ERROR'}:RECONNECTING:NOW`); sockets.relay?.start(); }, 60_000); @@ -213,18 +223,28 @@ export const startRelay = () => { // Retry in 60s setTimeout(() => { - log.debug(`☁️ RELAY:${message ?? 'GATEWAY_DOWN'}:RECONNECTING:NOW`); + // Another process has already kicked this off + if (isRelayConnecting) { + return; + } // Restart relay connection + isRelayConnecting = true; + log.debug(`☁️ RELAY:${message ?? 'GATEWAY_DOWN'}:RECONNECTING:NOW`); sockets.relay?.start(); }, 60_000); break; default: - log.debug(`☁️ RELAY:${message}:RECONNECTING:NOW`); + // Another process has already kicked this off + if (isRelayConnecting) { + return; + } // Restart relay connection + isRelayConnecting = true; + log.debug(`☁️ RELAY:${message}:RECONNECTING:NOW`); sockets.relay?.start(); break; }