diff --git a/lib/stream.js b/lib/stream.js index 53706cc90..c3a793691 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -84,13 +84,13 @@ function createWebSocketStream(ws, options) { // Prevent `ws.terminate()` from being called by `duplex._destroy()`. // - // - If the state of the `WebSocket` connection is `CONNECTING`, - // `ws.terminate()` is a noop as no socket was assigned. - // - Otherwise, the error was re-emitted from the listener of the `'error'` + // - If the `'error'` event is emitted before the `'open'` event, then + // `ws.terminate()` is a noop as no socket is assigned. + // - Otherwise, the error is re-emitted by the listener of the `'error'` // event of the `Receiver` object. The listener already closes the // connection by calling `ws.close()`. This allows a close frame to be // sent to the other peer. If `ws.terminate()` is called right after this, - // the close frame might not be sent. + // then the close frame might not be sent. terminateOnDestroy = false; duplex.destroy(err); });