Skip to content

Commit

Permalink
Emit disconnected event instead of error when ECONNRESET
Browse files Browse the repository at this point in the history
ECONNRESET means the other side of the TCP conversation abruptly
closed its end of the connection.

If we get an ECONNRESET error from the proxy request and the
socket is destroyed this means that the client has closed
his connection, and emit this as an error can lead to
confusion and hacks to filter that kind of message.

I think that the best we can do is abort and emit another event,
so if any caller wants to handle with that kind of error, he can
by listen the disconnected event.

http-party#813
  • Loading branch information
Deividy committed Feb 24, 2016
1 parent e1b2f4c commit 7d68d02
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/http-proxy/passes/web-incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ web_o = Object.keys(web_o).map(function(pass) {
req.on('error', proxyError);

// Error Handler
proxyReq.on('error', proxyError);
proxyReq.on('error', function (err) {
if (req.socket.destroyed && err.code === 'ECONNRESET') {
server.emit('disconnected', err, req, res, options.target);
proxyReq.abort();
} else {
proxyError(err);
}
});


function proxyError (err){
if (clb) {
Expand Down
2 changes: 1 addition & 1 deletion test/lib-http-proxy-passes-web-incoming-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ describe('#createProxyServer.web() using own http server', function () {

var started = new Date().getTime();
function requestHandler(req, res) {
proxy.once('error', function (err, errReq, errRes) {
proxy.once('disconnected', function (err, errReq, errRes) {
proxyServer.close();
expect(err).to.be.an(Error);
expect(errReq).to.be.equal(req);
Expand Down

0 comments on commit 7d68d02

Please sign in to comment.