Skip to content

Commit

Permalink
Emit disconnected event instead of error when ECONNRESET (#966)
Browse files Browse the repository at this point in the history
* Emit disconnected event instead of error when ECONNRESET

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.

#813

* code standards, move econnreset check, change ev name
  • Loading branch information
Deividy authored and jcrugzz committed Jun 3, 2016
1 parent 3e96636 commit 42df703
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/http-proxy/passes/web-incoming.js
Expand Up @@ -137,6 +137,11 @@ web_o = Object.keys(web_o).map(function(pass) {
proxyReq.on('error', proxyError);

function proxyError (err){
if (req.socket.destroyed && err.code === 'ECONNRESET') {
server.emit('econnreset', err, req, res, options.target);
return proxyReq.abort();
}

if (clb) {
clb(err, req, res, options.target);
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/lib-http-proxy-passes-web-incoming-test.js
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('econnreset', function (err, errReq, errRes) {
proxyServer.close();
expect(err).to.be.an(Error);
expect(errReq).to.be.equal(req);
Expand Down

0 comments on commit 42df703

Please sign in to comment.