fix: ensure we're only reconnecting one connection

This commit is contained in:
Alexis
2021-09-15 15:41:47 +09:30
parent 250d65187a
commit 346722b2d0

View File

@@ -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;
}