From 0d5e6c259eee5e331c5cef92246888745edda5a4 Mon Sep 17 00:00:00 2001 From: enisdenjo Date: Thu, 10 Dec 2020 18:23:59 +0100 Subject: [PATCH] fix(client): No retries when disposed --- src/client.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index b59a2650..abc4ef48 100644 --- a/src/client.ts +++ b/src/client.ts @@ -246,6 +246,7 @@ export function createClient(options: ClientOptions): Client { })(); let state = { + disposed: false, socket: null as WebSocket | null, acknowledged: false, locks: 0, @@ -489,8 +490,8 @@ export function createClient(options: ClientOptions): Client { throw errOrCloseEvent; } - // normal closure is disposal, shouldnt try again - if (errOrCloseEvent.code === 1000) { + // already disposed or normal closure, shouldnt try again + if (state.disposed || errOrCloseEvent.code === 1000) { return false; } @@ -633,6 +634,7 @@ export function createClient(options: ClientOptions): Client { }; }, dispose() { + state.disposed = true; state.socket?.close(1000, 'Normal Closure'); emitter.reset(); },