From c76b17d3b327fb55ef76770d4825e02ab8f26ad1 Mon Sep 17 00:00:00 2001 From: DD Date: Mon, 20 Mar 2023 21:20:48 +0200 Subject: [PATCH] fix(WebSocketShard): don't close in #destroy when status is connecting (#9254) --- packages/ws/src/ws/WebSocketShard.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/ws/src/ws/WebSocketShard.ts b/packages/ws/src/ws/WebSocketShard.ts index f7cf67080..11e6ebba2 100644 --- a/packages/ws/src/ws/WebSocketShard.ts +++ b/packages/ws/src/ws/WebSocketShard.ts @@ -224,8 +224,7 @@ export class WebSocketShard extends AsyncEventEmitter { // Prevent a reconnection loop by unbinding the main close event this.connection.removeAllListeners('close'); - const shouldClose = - this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING; + const shouldClose = this.connection.readyState === WebSocket.OPEN; this.debug([ 'Connection status during destroy', @@ -301,7 +300,7 @@ export class WebSocketShard extends AsyncEventEmitter { // If the error is handled, we can just try to reconnect await this.destroy({ code: CloseCodes.Normal, - reason: 'Something timed out', + reason: 'Something timed out or went wrong while waiting for an event', recover: WebSocketShardDestroyRecovery.Reconnect, });