reconnecting-websocket icon indicating copy to clipboard operation
reconnecting-websocket copied to clipboard

Bug: `_handleError` does not bubble up actual error reason (e.g. `ECONNREFUSED`)

Open titanism opened this issue 7 months ago • 0 comments

As per https://github.com/vitalets/websocket-as-promised/issues/47 we discovered there's a bug in reconnecting-websocket as well as @opensumi/reconnecting-websocket:

https://github.com/opensumi/reconnecting-websocket/blob/6010e6b99967c2977c7abc7d0a1845245c101eb2/reconnecting-websocket.ts#L478-L489

Needs changed to:

    private _handleError = (event: Events.ErrorEvent) => {
        this._debug('error event', event.message);
-        this._disconnect(undefined, event.message === 'TIMEOUT' ? 'timeout' : undefined);
+        this._disconnect(undefined, event.message === 'TIMEOUT' ? 'timeout' : event.message);

        if (this.onerror) {
            this.onerror(event);
        }
        this._debug('exec error listeners');
        this._listeners.error.forEach(listener => this._callEventListener(event, listener));

        this._connect();
    };

Otherwise the err.reason will be undefined and not bubble up to the error listener, and you won't have a clue as to what happened.

cc @bytemain

titanism avatar Jul 02 '24 22:07 titanism