Skip to content

Commit 23c9d4f

Browse files
committed
Fix error handler issue.
1 parent 2dbd40c commit 23c9d4f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/rsocket-router/src/router/transport/WebsocketDuplexConnection.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ export class WebsocketDuplexConnection extends Deferred implements DuplexConnect
6262
return;
6363
}
6464

65-
this.websocketDuplex.removeAllListeners();
65+
// Important: do not remove the error handler here.
66+
// That causes uncaught error handlers in some edge cases.
67+
this.websocketDuplex.removeAllListeners('close');
68+
this.websocketDuplex.removeAllListeners('data');
69+
6670
this.websocketDuplex.end();
6771

6872
super.close(error);
@@ -88,13 +92,15 @@ export class WebsocketDuplexConnection extends Deferred implements DuplexConnect
8892
}
8993
}
9094

91-
private handleClosed = (e: WebSocket.CloseEvent): void => {
92-
this.close(new Error(e.reason || 'WebsocketDuplexConnection: Socket closed unexpectedly.'));
95+
private handleClosed = (e?: WebSocket.CloseEvent): void => {
96+
this.close(new Error(e?.reason || 'WebsocketDuplexConnection: Socket closed unexpectedly.'));
9397
};
9498

9599
private handleError = (e: WebSocket.ErrorEvent): void => {
96100
logger.error(`Error in WebSocket duplex connection: ${e}`);
97-
this.close(e.error);
101+
if (!this.done) {
102+
this.close(e.error);
103+
}
98104
};
99105

100106
private handleMessage = (buffer: Buffer): void => {

0 commit comments

Comments
 (0)