Skip to content

Commit 42df703

Browse files
Deividyjcrugzz
authored andcommitted
Emit disconnected event instead of error when ECONNRESET (#966)
* 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
1 parent 3e96636 commit 42df703

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ web_o = Object.keys(web_o).map(function(pass) {
137137
proxyReq.on('error', proxyError);
138138

139139
function proxyError (err){
140+
if (req.socket.destroyed && err.code === 'ECONNRESET') {
141+
server.emit('econnreset', err, req, res, options.target);
142+
return proxyReq.abort();
143+
}
144+
140145
if (clb) {
141146
clb(err, req, res, options.target);
142147
} else {

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('econnreset', 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)