mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
fix(WebSocketShard#destroy): wait for close and cleanup listeners (#8479)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -185,7 +185,18 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
|
|||||||
this.connection &&
|
this.connection &&
|
||||||
(this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING)
|
(this.connection.readyState === WebSocket.OPEN || this.connection.readyState === WebSocket.CONNECTING)
|
||||||
) {
|
) {
|
||||||
|
// No longer need to listen to messages
|
||||||
|
this.connection.removeAllListeners('message');
|
||||||
|
// Prevent a reconnection loop by unbinding the main close event
|
||||||
|
this.connection.removeAllListeners('close');
|
||||||
this.connection.close(options.code, options.reason);
|
this.connection.close(options.code, options.reason);
|
||||||
|
|
||||||
|
// Actually wait for the connection to close
|
||||||
|
await once(this.connection, 'close');
|
||||||
|
|
||||||
|
// Lastly, remove the error event.
|
||||||
|
// Doing this earlier would cause a hard crash in case an error event fired on our `close` call
|
||||||
|
this.connection.removeAllListeners('error');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.status = WebSocketShardStatus.Idle;
|
this.status = WebSocketShardStatus.Idle;
|
||||||
|
|||||||
Reference in New Issue
Block a user