mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
fix(WebSocketShard): either start close timeout or emit destroyed but never both (#8956)
* fix(WebSocketShard): only close timeout or destroy * Remove optional chaining Co-authored-by: Voxelli <69213593+legendhimself@users.noreply.github.com> Co-authored-by: Voxelli <69213593+legendhimself@users.noreply.github.com>
This commit is contained in:
@@ -835,23 +835,27 @@ class WebSocketShard extends EventEmitter {
|
|||||||
);
|
);
|
||||||
this.connection.terminate();
|
this.connection.terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit the destroyed event if needed
|
// Emit the destroyed event if needed
|
||||||
if (emit) this._emitDestroyed();
|
if (emit) {
|
||||||
|
this._emitDestroyed();
|
||||||
|
} else if (
|
||||||
|
this.connection.readyState === WebSocket.CLOSING ||
|
||||||
|
this.connection.readyState === WebSocket.CLOSED
|
||||||
|
) {
|
||||||
|
this.closeEmitted = false;
|
||||||
|
this.debug(
|
||||||
|
`[WebSocket] Adding a WebSocket close timeout to ensure a correct WS reconnect.
|
||||||
|
Timeout: ${this.manager.client.options.closeTimeout}ms`,
|
||||||
|
);
|
||||||
|
this.setWsCloseTimeout(this.manager.client.options.closeTimeout);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (emit) {
|
} else if (emit) {
|
||||||
// We requested a destroy, but we had no connection. Emit destroyed
|
// We requested a destroy, but we had no connection. Emit destroyed
|
||||||
this._emitDestroyed();
|
this._emitDestroyed();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.connection?.readyState === WebSocket.CLOSING || this.connection?.readyState === WebSocket.CLOSED) {
|
|
||||||
this.closeEmitted = false;
|
|
||||||
this.debug(
|
|
||||||
`[WebSocket] Adding a WebSocket close timeout to ensure a correct WS reconnect.
|
|
||||||
Timeout: ${this.manager.client.options.closeTimeout}ms`,
|
|
||||||
);
|
|
||||||
this.setWsCloseTimeout(this.manager.client.options.closeTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Step 2: Null the connection object
|
// Step 2: Null the connection object
|
||||||
this.connection = null;
|
this.connection = null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user