Skip to content

Commit

Permalink
fix(client): No retries when disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Dec 10, 2020
1 parent bf1b537 commit 0d5e6c2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/client.ts
Expand Up @@ -246,6 +246,7 @@ export function createClient(options: ClientOptions): Client {
})();

let state = {
disposed: false,
socket: null as WebSocket | null,
acknowledged: false,
locks: 0,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -633,6 +634,7 @@ export function createClient(options: ClientOptions): Client {
};
},
dispose() {
state.disposed = true;
state.socket?.close(1000, 'Normal Closure');
emitter.reset();
},
Expand Down

0 comments on commit 0d5e6c2

Please sign in to comment.