diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index f28abcb84..72d2a83a5 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -611,12 +611,17 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // connections. // function proxyError (err) { - reverseProxy.end(); - if (self.emit('webSocketProxyError', req, socket, head)) { - return; - } + reverseProxy.destroy(); + + process.nextTick(function () { + // + // Destroy the incoming socket in the next tick, in case the error handler + // wants to write to it. + // + socket.destroy(); + }); - socket.end(); + self.emit('webSocketProxyError', req, socket, head); } //