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

How to detect a broken HTTP/TCP connection #16443

Closed
julien-f opened this issue Oct 24, 2017 · 5 comments
Closed

How to detect a broken HTTP/TCP connection #16443

julien-f opened this issue Oct 24, 2017 · 5 comments
Labels
question Issues that look for answers. wrong repo Issues that should be opened in another repository.

Comments

@julien-f
Copy link
Contributor

Hi,

My use case: I have a long HTTP request and I want to get an error when the connection fails instead of waiting indefinitely.

I tried to use keepAlive to help detecting whether the connection is up or not but it does not seem to be working.

Is there anything I'm missing?

Test repo: https://github.com/julien-f/socket-keepalive-tests/

@jasnell
Copy link
Member

jasnell commented Oct 24, 2017

Questions like this are better directed at the nodejs/help repo (just as an fyi...)

keepAlive is an indication of whether the HTTP keep-alive mechanism is being used. It will not tell you the health of the current connection. Currently, there is no mechanism for determining if a connection is still active. You essentially need to attempt to read/write to it and deal with the error if it's not. You can set a timeout handler to set some action if there has been no activity within a given period of time, but that can miss disconnections also.

@jasnell jasnell added the question Issues that look for answers. label Oct 24, 2017
@julien-f
Copy link
Contributor Author

My bad, I didn't know about this repo.

I'm talking about TCP keep-alive, not HTTP keep-alive 😉

I'm reluctant to use a timeout because I will miss the response and will not be able to tell if the RPC method I called was successful 😕

@Ginden
Copy link

Ginden commented Oct 26, 2017

Consider implementing some kind of heartbeat.

@julien-f
Copy link
Contributor Author

Unfortunately I don't have any control on the HTTP server 😢

AFAIU, TCP is a connected protocol, I would be surprised if it is unable to detect a connection failure…

@bnoordhuis
Copy link
Member

You'd be surprised. I'll close this out but if you want to continue the conversation, please move it over to the help repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. wrong repo Issues that should be opened in another repository.
Projects
None yet
Development

No branches or pull requests

4 participants