Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop in error handler #329

Closed
apirila opened this issue Oct 5, 2018 · 0 comments · Fixed by #332
Closed

Infinite loop in error handler #329

apirila opened this issue Oct 5, 2018 · 0 comments · Fixed by #332

Comments

@apirila
Copy link
Contributor

apirila commented Oct 5, 2018

The error handler will cause an infinite loop. HandleSocketError method is attached as an error handler:

    this.socket.on('error', this.handleSocketError.bind(this));

The handler will destroy the socket with an error argument. But according to Node's documentation in this case the error handler is invoked. See here This will again invoke the handler ad infinitum.

WebSocketConnection.prototype.handleSocketError = function(error) {
    this._debug('handleSocketError: %j', error);
    if (this.state === STATE_CLOSED) {
		// See https://github.com/theturtle32/WebSocket-Node/issues/288
        this._debug('  --- Socket \'error\' after \'close\'');
        return;
    }
    this.closeReasonCode = WebSocketConnection.CLOSE_REASON_ABNORMAL;
    this.closeDescription = 'Socket Error: ' + error.syscall + ' ' + error.code;
    this.connected = false;
    this.state = STATE_CLOSED;
    this.fragmentationSize = 0;
    if (utils.eventEmitterListenerCount(this, 'error') > 0) {
        this.emit('error', error);
    }
    this.socket.destroy(error); /* <== HERE */
    this._debug.printOutput();
};
apirila added a commit to apirila/WebSocket-Node that referenced this issue Oct 5, 2018
@ibc ibc closed this as completed in #332 Dec 3, 2019
ibc pushed a commit that referenced this issue Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant