From 0d00b06af307dc5c70c36e89617a08486eb665e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Ma=C5=82ecki?= Date: Tue, 24 Jul 2012 16:30:51 +0200 Subject: [PATCH] [fix] `destroy()` websockets in case of an error Not doing so caused websockets in `CLOSE_WAIT` to pile up and cause proxy to exceed open file descriptor limit. --- lib/node-http-proxy/http-proxy.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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); } //