Skip to content

Commit d8ea687

Browse files
committed
Close outgoing ws if incoming ws emits error
Fixes http-party#559, which contains a full reproduction recipe.
1 parent 0b223ab commit d8ea687

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/http-proxy/passes/ws-incoming.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,16 @@ var passes = exports;
8888
common.setupOutgoing(options.ssl || {}, options, req)
8989
);
9090
// Error Handler
91-
proxyReq.on('error', onError);
91+
proxyReq.on('error', onOutgoingError);
9292

9393
proxyReq.on('upgrade', function(proxyRes, proxySocket, proxyHead) {
94-
proxySocket.on('error', onError);
94+
proxySocket.on('error', onOutgoingError);
95+
// The pipe below will end proxySocket if socket closes cleanly, but not
96+
// if it errors (eg, vanishes from the net and starts returning
97+
// EHOSTUNREACH). We need to do that explicitly.
98+
socket.on('error', function () {
99+
proxySocket.end();
100+
});
95101

96102
common.setupSocket(proxySocket);
97103

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

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

109-
function onError(err) {
115+
function onOutgoingError(err) {
110116
if (clb) {
111117
clb(err, req, socket);
112118
} else {

0 commit comments

Comments
 (0)