diff --git a/lib/websocket.js b/lib/websocket.js index e17d6c1a7..cd8929bdc 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -901,6 +901,8 @@ function socketOnError() { this.removeListener('error', socketOnError); this.on('error', NOOP); - websocket.readyState = WebSocket.CLOSING; - this.destroy(); + if (websocket) { + websocket.readyState = WebSocket.CLOSING; + this.destroy(); + } }