Skip to content

Commit

Permalink
memory leak fix in closing of the scokets
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and indexzero committed Mar 9, 2013
1 parent 013cb2e commit 2055d0c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/node-http-proxy/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2055d0c

Please sign in to comment.