Skip to content

Commit 7d68d02

Browse files
committed
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. http-party#813
1 parent e1b2f4c commit 7d68d02

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,15 @@ web_o = Object.keys(web_o).map(function(pass) {
132132
req.on('error', proxyError);
133133

134134
// Error Handler
135-
proxyReq.on('error', proxyError);
135+
proxyReq.on('error', function (err) {
136+
if (req.socket.destroyed && err.code === 'ECONNRESET') {
137+
server.emit('disconnected', err, req, res, options.target);
138+
proxyReq.abort();
139+
} else {
140+
proxyError(err);
141+
}
142+
});
143+
136144

137145
function proxyError (err){
138146
if (clb) {

test/lib-http-proxy-passes-web-incoming-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ describe('#createProxyServer.web() using own http server', function () {
229229

230230
var started = new Date().getTime();
231231
function requestHandler(req, res) {
232-
proxy.once('error', function (err, errReq, errRes) {
232+
proxy.once('disconnected', function (err, errReq, errRes) {
233233
proxyServer.close();
234234
expect(err).to.be.an(Error);
235235
expect(errReq).to.be.equal(req);

0 commit comments

Comments
 (0)