Skip to content

Commit 15039ab

Browse files
committed
fix: detect disconnect on transport read failure
1 parent 1ac1bf9 commit 15039ab

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/session.ts

Lines changed: 6 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,8 @@ export class Session {
9899
return;
99100
}
100101

101-
throw err;
102+
// Transport read failed, treat it as a disconnect.
103+
await this.markDisconnected(err instanceof globalThis.Error ? err.message : String(err));
102104
}
103105
})();
104106
}
@@ -344,6 +346,9 @@ export class Session {
344346
}
345347

346348
private async markDisconnected(reason?: string) {
349+
if (this._disconnected) return;
350+
this._disconnected = true;
351+
347352
if (this._disconnectCallbacks.length > 0) {
348353
await Promise.all(this._disconnectCallbacks.map(cb => cb(reason)));
349354
}

0 commit comments

Comments
 (0)