From 5a4bdfda5062055ca8ab4bfb68a8d7bc99067e10 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Sun, 28 Jun 2026 21:25:12 -0500 Subject: [PATCH] fix(shared): close websocket clients deterministically Ensure intentional client closes mark the transport closed and reject pending RPCs immediately instead of relying on a browser close event that can be ignored after the socket reference is cleared. --- apps/shared/src/json-rpc-gateway.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/shared/src/json-rpc-gateway.ts b/apps/shared/src/json-rpc-gateway.ts index a138edbb1c2..4cc869f1519 100644 --- a/apps/shared/src/json-rpc-gateway.ts +++ b/apps/shared/src/json-rpc-gateway.ts @@ -185,8 +185,19 @@ export class JsonRpcGatewayClient { } close(): void { - this.socket?.close() - this.socket = null + const socket = this.socket + + if (!socket) { + return + } + + try { + socket.close() + } finally { + this.socket = null + this.setState('closed') + this.rejectAllPending(new Error(this.options.closedErrorMessage)) + } } on

(type: GatewayEventName, handler: (event: GatewayEvent

) => void): () => void {