Skip to content

Commit 2009a99

Browse files
committed
fix: detect disconnect on transport read failure
1 parent 1ac1bf9 commit 2009a99

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

lib/session.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export class Session {
4646
private _wampSession: WAMPSession;
4747
private _idGen: SessionScopeIDGenerator = new SessionScopeIDGenerator();
4848
private _disconnectCallbacks: Array<(reason?: string) => Promise<void>> = [];
49+
private _disconnected = false;
4950

5051
private _callRequests: Map<number, {
5152
resolve: (value: Result) => void,
@@ -98,7 +99,10 @@ export class Session {
9899
return;
99100
}
100101

101-
throw err;
102+
// Transport read failed (socket closed/errored) — treat this the
103+
// same as a disconnect, mirroring xconn-go's waitForRouterMessages,
104+
// instead of relying solely on the peer's own onDisconnect wiring.
105+
await this.markDisconnected(err instanceof globalThis.Error ? err.message : String(err));
102106
}
103107
})();
104108
}
@@ -344,6 +348,9 @@ export class Session {
344348
}
345349

346350
private async markDisconnected(reason?: string) {
351+
if (this._disconnected) return;
352+
this._disconnected = true;
353+
347354
if (this._disconnectCallbacks.length > 0) {
348355
await Promise.all(this._disconnectCallbacks.map(cb => cb(reason)));
349356
}

0 commit comments

Comments
 (0)