Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit disconnected event instead of error when ECONNRESET #966

Merged
merged 2 commits into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should contain this logic in the proxyError function and change the error listener for req if we are going to keep it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be 2 spaces not 4 spaces for indentation.

server.emit('disconnected', err, req, res, options.target);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe make the event econnreset? its more for logging purposes then anything

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