Close outgoing ws if incoming ws emits error

Fixes #559, which contains a full reproduction recipe.
This commit is contained in:
David Glasser 2014-01-22 15:40:40 -08:00 committed by Jarrett Cruger
parent daad4703f3
commit 4c3ba74c4e

View File

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