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

Conversation

Deividy
Copy link
Contributor

@Deividy Deividy commented Feb 24, 2016

Hello folks,
This is my first contribution, if there is anything wrong with my PR, please let me know.

We've been using node-http-proxy in our prod server since 3 years now and its working as a charm (thank you!), but everyday we got our log files full of socket hang up messages, so I come here dig code and found an issue for that: #813.

To me, this looks like a bug also, we should not send as an error a disconnection between the client, so I made this PR using the info in the issue.

I'm not sure if emit a disconnected event is the best approach, or if you guys want something more elaborate for that. Please, let me know your thoughts.

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
@jcrugzz
Copy link
Contributor

jcrugzz commented Feb 25, 2016

@Deividy thanks for the contribution! I saw you did some investigation on removing the req.on('error') listener. The proxyReq error event was still triggered when the client disconnected when removing it still? I can see this can still be an issue when the client request itself timed out but was curious :). Will comment

@@ -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.

@Deividy
Copy link
Contributor Author

Deividy commented Feb 25, 2016

Yep, the proxyReq error was still triggered even removing the listen req.on('error'), my test case was refresh the browser window like crazy, this can trigger the socket hang up false alarms, btw, this should be good to have a test case.

Thanks for the comments, I made the tweaks.
About the req listener, what we can do about that? Maybe emit some other event or just remove it? I saw a PR removing it, don't know if I touch that or not.

@JSteunou
Copy link

Maybe missing a line of comment to explain why this function has an early return instead of calling callback or triggering error event. Otherwise looks very good, thank you for this PR!

@JSteunou
Copy link

JSteunou commented Apr 8, 2016

@jcrugzz good to go?

@jcrugzz
Copy link
Contributor

jcrugzz commented Jun 3, 2016

@Deividy thank you for your work. Will merge this. id like to rebase the branch that removes teh req.on('error') listener and see how it behaves.

@anujtewari
Copy link

@Deividy and @jcrugzz - can the same be used for ECONNREFUSED?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants