Skip to content

Commit

Permalink
close socket if upstream request fails
Browse files Browse the repository at this point in the history
adds socket.end() to on('error') handlers for proxyReq and proxySocket
  • Loading branch information
minrk committed Oct 1, 2014
1 parent 43c6f0c commit e894f63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/http-proxy/passes/ws-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ var passes = exports;
} else {
server.emit('error', err, req, socket);
}
socket.end();
}
}

Expand Down
9 changes: 8 additions & 1 deletion test/lib-http-proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,24 @@ describe('lib/http-proxy.js', function() {
client.on('open', function () {
client.send('hello there');
});

var count = 0;
maybe_done = function () {
count += 1;
if (count === 2) done();
}

client.on('error', function (err) {
expect(err).to.be.an(Error);
expect(err.code).to.be('ECONNRESET');
maybe_done();
});

proxy.on('error', function (err) {
expect(err).to.be.an(Error);
expect(err.code).to.be('ECONNREFUSED');
proxyServer.close();
done();
maybe_done();
});
});

Expand Down

0 comments on commit e894f63

Please sign in to comment.