Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Close outgoing ws if incoming ws emits error
Fixes #559, which contains a full reproduction recipe.
  • Loading branch information
glasser authored and jcrugzz committed Jan 28, 2014
1 parent daad470 commit 4c3ba74
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/http-proxy/passes/ws-incoming.js
Expand Up @@ -88,10 +88,16 @@ var passes = exports;
common.setupOutgoing(options.ssl || {}, options, req)
);
// Error Handler
proxyReq.on('error', onError);
proxyReq.on('error', onOutgoingError);

proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
proxySocket.on('error', onError);
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
// EHOSTUNREACH). We need to do that explicitly.
socket.on('error', function () {
proxySocket.end();
});

common.setupSocket(proxySocket);

Expand All @@ -106,7 +112,7 @@ var passes = exports;

return proxyReq.end(); // XXX: CHECK IF THIS IS THIS CORRECT

function onError(err) {
function onOutgoingError(err) {
if (clb) {
clb(err, req, socket);
} else {
Expand Down

0 comments on commit 4c3ba74

Please sign in to comment.