From 7e8e7d0b00a248aac2a3945a0a0f8414fb644e50 Mon Sep 17 00:00:00 2001 From: Tiago Siebler Date: Tue, 6 Aug 2024 11:06:07 +0100 Subject: [PATCH] fix(): multi-connection lock blocks reconnect --- src/lib/BaseWSClient.ts | 5 ++++- src/lib/websocket/WsStore.types.ts | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/BaseWSClient.ts b/src/lib/BaseWSClient.ts index 236c6ea..3efa84e 100644 --- a/src/lib/BaseWSClient.ts +++ b/src/lib/BaseWSClient.ts @@ -370,7 +370,9 @@ export abstract class BaseWebsocketClient< return { wsKey }; } - if (this.wsStore.isConnectionAttemptInProgress(wsKey)) { + if ( + this.wsStore.isConnectionState(wsKey, WsConnectionStateEnum.CONNECTING) + ) { this.logger.error( 'Refused to connect to ws, connection attempt already active', { ...WS_LOGGER_CATEGORY, wsKey }, @@ -468,6 +470,7 @@ export abstract class BaseWebsocketClient< private reconnectWithDelay(wsKey: TWSKey, connectionDelayMs: number) { this.clearTimers(wsKey); + if (!this.wsStore.isConnectionAttemptInProgress(wsKey)) { this.setWsState(wsKey, WsConnectionStateEnum.RECONNECTING); } diff --git a/src/lib/websocket/WsStore.types.ts b/src/lib/websocket/WsStore.types.ts index c48d22b..280129f 100644 --- a/src/lib/websocket/WsStore.types.ts +++ b/src/lib/websocket/WsStore.types.ts @@ -6,6 +6,7 @@ export enum WsConnectionStateEnum { CONNECTED = 2, CLOSING = 3, RECONNECTING = 4, + // ERROR_RECONNECTING = 5, // ERROR = 5, }