Skip to content
Permalink
Browse files

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 22, 2014
1 parent daad470 commit 4c3ba74c4e99f03eed84f4d34844870845d96790
Showing with 9 additions and 3 deletions.
  1. +9 −3 lib/http-proxy/passes/ws-incoming.js
@@ -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);

@@ -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 {

0 comments on commit 4c3ba74

Please sign in to comment.
You can’t perform that action at this time.