Skip to content

Commit

Permalink
[fix minor] Prevent crashes from attempting to remove listeners more …
Browse files Browse the repository at this point in the history
…than once when proxying websocket requests.
  • Loading branch information
indexzero committed Mar 9, 2013
1 parent 2055d0c commit a681493
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/node-http-proxy/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// the appropriate events.
//
function onUpgrade (reverseProxy, proxySocket) {
var detached;

if (!reverseProxy) {
proxySocket.end();
socket.end();
Expand Down Expand Up @@ -543,12 +545,15 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// from `reverseProxy` and `proxySocket`.
//
function detach() {
proxySocket.destroySoon();
proxySocket.removeListener('end', listeners.onIncomingClose);
proxySocket.removeListener('data', listeners.onIncoming);
reverseProxy.incoming.socket.destroySoon();
reverseProxy.incoming.socket.removeListener('end', listeners.onOutgoingClose);
reverseProxy.incoming.socket.removeListener('data', listeners.onOutgoing);
if (!detached) {
detached = true;
proxySocket.destroySoon();
proxySocket.removeListener('end', listeners.onIncomingClose);
proxySocket.removeListener('data', listeners.onIncoming);
reverseProxy.incoming.socket.destroySoon();
reverseProxy.incoming.socket.removeListener('end', listeners.onOutgoingClose);
reverseProxy.incoming.socket.removeListener('data', listeners.onOutgoing);
}
}

//
Expand Down

0 comments on commit a681493

Please sign in to comment.