From 2055d0c8ec16699ffb06adf6d64d9506920b2071 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Jul 2012 14:25:54 -0700 Subject: [PATCH] memory leak fix in closing of the scokets --- lib/node-http-proxy/http-proxy.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 7e97041..ffc2c9d 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -551,24 +551,31 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) reverseProxy.incoming.socket.removeListener('data', listeners.onOutgoing); } - // + // // If the incoming `proxySocket` socket closes, then // detach all event listeners. // - proxySocket.on('end', listeners.onIncomingClose = function() { + listeners.onIncomingClose = function() { + reverseProxy.incoming.socket.destroy(); detach(); // Emit the `end` event now that we have completed proxying - self.emit('websocket:end', req, socket, head); - }); + self.emit('websocket:end', req, socket, head); + } // // If the `reverseProxy` socket closes, then detach all // event listeners. - // - reverseProxy.incoming.socket.on('end', listeners.onOutgoingClose = function() { - detach(); - }); + // + listeners.onOutgoingClose = function() { + proxySocket.destroy(); + detach(); + } + + proxySocket.on('end', listeners.onIncomingClose); + proxySocket.on('close', listeners.onIncomingClose); + reverseProxy.incoming.socket.on('end', listeners.onOutgoingClose); + reverseProxy.incoming.socket.on('close', listeners.onOutgoingClose); } function getPort (port) {