Skip to content

Commit

Permalink
Fix socket leaks when FIN packet isn't responded to
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and mmalecki committed Jul 24, 2012
1 parent 0d00b06 commit 24b8406
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/node-http-proxy/http-proxy.js
Expand Up @@ -500,8 +500,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
}
catch (ex) {
detach();
reverseProxy.incoming.socket.end();
proxySocket.end();
}
}
});
Expand Down Expand Up @@ -532,8 +530,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
}
catch (ex) {
detach();
proxySocket.end();
socket.end();
}
});

Expand All @@ -542,8 +538,10 @@ 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);
}
Expand All @@ -553,7 +551,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// detach all event listeners.
//
proxySocket.on('end', listeners.onIncomingClose = function() {
reverseProxy.incoming.socket.end();
detach();

// Emit the `end` event now that we have completed proxying
Expand All @@ -565,7 +562,6 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
// event listeners.
//
reverseProxy.incoming.socket.on('end', listeners.onOutgoingClose = function() {
proxySocket.end();
detach();
});
}
Expand Down

0 comments on commit 24b8406

Please sign in to comment.