reconnecting-websocket
reconnecting-websocket copied to clipboard
Bug: `_disconnect` causes uncaught exception and process to crash if using `ws` library
There is a bug in the codebase right now in that _disconnect
is invoked which subsequently calls this._ws.close
. Despite there being a try/catch wrapper, if you use the ws
library, an exception is thrown and your process will exit.
ReconnectingWebSocket.prototype._disconnect = function (code, reason) {
if (code === undefined) {
code = 1000;
}
this._clearTimeouts();
if (!this._ws) {
return;
}
this._removeListeners();
try {
+ if (this._ws.readyState === ReconnectingWebSocket.OPEN) {
+ this._ws.close(code, reason);
+ }
- this._ws.close(code, reason);
this._handleClose(new CloseEvent(code, reason, this));
} catch (err) {
console.log('das error', err);
}
};
cc @bytemain @abdelmagied94 @Zerounary can you please merge this fix into your library at https://github.com/opensumi/reconnecting-websocket for the npm package @opensumi/reconnecting-websocket
and patch version bump and publish to npm afterwards to v4.4.1 (it currently on v4.4.0)