memory leak fix in closing of the scokets

This commit is contained in:
unknown 2012-07-30 14:25:54 -07:00 committed by indexzero
parent 013cb2e0c2
commit 2055d0c8ec

View File

@ -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) {