Skip to content

Commit

Permalink
close websocket if proxyReq is closed before upgrade
Browse files Browse the repository at this point in the history
avoids leaving client sockets open when upstream
connections are rejected.
  • Loading branch information
minrk committed Sep 30, 2014
1 parent 7730548 commit c49206e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/http-proxy/passes/ws-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,19 @@ var passes = exports;
);
// Error Handler
proxyReq.on('error', onOutgoingError);
var upgraded = false;
proxyReq.on('close', function () {
if (!upgraded) {
try {
socket.end();
} catch (e) {
// ignore failure to teardown socket
}
}
});

proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
upgraded = true;
proxySocket.on('error', onOutgoingError);
// The pipe below will end proxySocket if socket closes cleanly, but not
// if it errors (eg, vanishes from the net and starts returning
Expand Down

0 comments on commit c49206e

Please sign in to comment.