fix(WebSocketManager): always emit shardDisconnect on unresumable close (#10826)

This commit is contained in:
Qjuh
2025-04-28 22:43:50 +02:00
committed by GitHub
parent e3c247e423
commit 37ef57b880

View File

@@ -36,10 +36,13 @@ const BeforeReadyWhitelist = [
const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete]; const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
const UNRESUMABLE_CLOSE_CODES = [ const UNRECOVERABLE_CLOSE_CODES = [
CloseCodes.Normal, GatewayCloseCodes.AuthenticationFailed,
GatewayCloseCodes.AlreadyAuthenticated, GatewayCloseCodes.InvalidShard,
GatewayCloseCodes.InvalidSeq, GatewayCloseCodes.ShardingRequired,
GatewayCloseCodes.InvalidAPIVersion,
GatewayCloseCodes.InvalidIntents,
GatewayCloseCodes.DisallowedIntents,
]; ];
const reasonIsDeprecated = 'the reason property is deprecated, use the code property to determine the reason'; const reasonIsDeprecated = 'the reason property is deprecated, use the code property to determine the reason';
@@ -242,7 +245,7 @@ class WebSocketManager extends EventEmitter {
this._ws.on(WSWebSocketShardEvents.Closed, ({ code, shardId }) => { this._ws.on(WSWebSocketShardEvents.Closed, ({ code, shardId }) => {
const shard = this.shards.get(shardId); const shard = this.shards.get(shardId);
shard.emit(WebSocketShardEvents.Close, { code, reason: reasonIsDeprecated, wasClean: true }); shard.emit(WebSocketShardEvents.Close, { code, reason: reasonIsDeprecated, wasClean: true });
if (UNRESUMABLE_CLOSE_CODES.includes(code) && this.destroyed) { if (UNRECOVERABLE_CLOSE_CODES.includes(code)) {
shard.status = Status.Disconnected; shard.status = Status.Disconnected;
/** /**
* Emitted when a shard's WebSocket disconnects and will no longer reconnect. * Emitted when a shard's WebSocket disconnects and will no longer reconnect.
@@ -251,7 +254,7 @@ class WebSocketManager extends EventEmitter {
* @param {number} id The shard id that disconnected * @param {number} id The shard id that disconnected
*/ */
this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId); this.client.emit(Events.ShardDisconnect, { code, reason: reasonIsDeprecated, wasClean: true }, shardId);
this.debug([`Shard not resumable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`], shardId); this.debug([`Shard not recoverable: ${code} (${GatewayCloseCodes[code] ?? CloseCodes[code]})`], shardId);
return; return;
} }