From d086f4bcbbe235f12f6fa2ddba5a8ce1342dac58 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sat, 26 Mar 2022 20:32:45 +0100 Subject: [PATCH] [minor] Make `abortHandshake()` emit the error in the next tick --- lib/websocket.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/websocket.js b/lib/websocket.js index 6fff935cb..dd67d7357 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -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 @@ -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'));