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.
This commit is contained in:
Brooklyn Nicholson 2026-06-28 21:25:12 -05:00
parent dfb561a3ae
commit 5a4bdfda50

View file

@ -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<P = unknown>(type: GatewayEventName, handler: (event: GatewayEvent<P>) => void): () => void {