Skip to content

Commit

Permalink
[minor] Make abortHandshake() emit the error in the next tick
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Mar 26, 2022
1 parent ff80d66 commit d086f4b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ function initAsClient(websocket, address, protocols, options) {
}

/**
* Emit the `'error'` and `'close'` event.
* Emit the `'error'` and `'close'` events.
*
* @param {WebSocket} websocket The WebSocket instance
* @param {Error} The error to emit
Expand Down Expand Up @@ -1018,8 +1018,7 @@ function abortHandshake(websocket, stream, message) {
stream.socket.destroy();
}

stream.once('abort', websocket.emitClose.bind(websocket));
websocket.emit('error', err);
process.nextTick(emitErrorAndClose, websocket, err);
} else {
stream.destroy(err);
stream.once('error', websocket.emit.bind(websocket, 'error'));
Expand Down

0 comments on commit d086f4b

Please sign in to comment.