refactor(WebSocketShard): clear ws session only when explicitly reconnecting (#11601)

* refactor(WebSocketShard): clear ws session when explicitly reconnecting

* fix(ws): check for .resuming code

* fix(ws): actually correct clear logic

* refactor: flip

Co-authored-by: Almeida <github@almeidx.dev>

---------

Co-authored-by: Almeida <github@almeidx.dev>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Denis-Adrian Cristea
2026-09-08 15:49:13 +00:00
committed by GitHub
co-authored by Almeida kodiakhq[bot]
parent 5f6cbf111e
commit a4116036be
2 changed files with 10 additions and 1 deletions
+6
View File
@@ -379,6 +379,12 @@ export class WebSocketManager extends AsyncEventEmitter<ManagerShardEventsMap> i
this.#token = token;
}
/**
* Destroys all shards
*
* @remarks
* To keep the shard(s) resumable, use the {@link CloseCodes.Resuming} code.
*/
public destroy(options?: Omit<WebSocketShardDestroyOptions, 'recover'>) {
return this.strategy.destroy(options);
}
+4 -1
View File
@@ -360,7 +360,10 @@ export class WebSocketShard extends AsyncEventEmitter<WebSocketShardEventsMap> {
this.failedToConnectDueToNetworkError = false;
// Clear session state if applicable
if (options.recover !== WebSocketShardDestroyRecovery.Resume) {
if (
(options.recover !== WebSocketShardDestroyRecovery.Resume && options.code !== CloseCodes.Resuming) ||
options.code === CloseCodes.Normal
) {
await this.strategy.updateSessionInfo(this.id, null);
}