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

Connection timeouts when Client lives a long time #44

Closed
mathstuf opened this issue Jan 12, 2017 · 5 comments
Closed

Connection timeouts when Client lives a long time #44

mathstuf opened this issue Jan 12, 2017 · 5 comments

Comments

@mathstuf
Copy link
Contributor

We have a Client object which we persist for a long time (ideal would be "forever") which has sporadic usage over the course of a day. After a longer period of being idle, we sometimes see connections immediately replied with a TCP RST packet causing a failure. Is it possible to manually flush the connection queue, remove the Keep-Alive header on the requests, or otherwise reset the connection pool after some timeout to avoid issues?

Cc: @bradking

@seanmonstar
Copy link
Owner

Currently, there isn't a good way to do this using hyper 0.10. Checking the status of a socket requires trying a read or write, and with blocking IO, that could mean that it just blocks the thread forever, since the server didn't have a request to reply to.

However, the pool in async hyper (soon to be 0.11) does have timeouts, along with cleaning out sockets that receive TCP FIN, so this should be easier to solve then.

Once hyper 0.11 is released, reqwest will make use of it internally, and keep the blocking API. This means we can take advantage of better timeouts.

@mathstuf
Copy link
Contributor Author

OK, so just creating new Client instances for each call is the best way until hyper 0.11 is used then?

@jbg
Copy link

jbg commented May 16, 2017

An alternative that would allow you to use keep-alives for multiple requests within a short time of each other (avoiding the overhead of creating a Client and connecting to the server separately for every single request) would be to catch the error and retry just the request that fails.

@mathstuf
Copy link
Contributor Author

The problem there is detecting legitimate connection resets versus resets from Client living too long.

@seanmonstar
Copy link
Owner

I've actually implemented a pretty solid solution into master, the fix shall be part of the v0.7 release. Each socket is checked using the same technique curl uses, by using select on the socket with a 0 timeout, so it should instantly check if the socket is already known to be dead.

It's of course still possible for a server to close the connection inbetween reqwest checking the local socket status and finally sending a request, but it should be much much less frequent.

dmfutcher pushed a commit to dmfutcher/rustfm-scrobble that referenced this issue Aug 26, 2017
seeekr pushed a commit to productioneer/rust-gitlab that referenced this issue Apr 15, 2019
This reverts MR !61. Now that reqwest 0.7 detects whether the client has
timed out or not, we only fail when the connection is lost between
checking the status of the client and the communication itself.

See seanmonstar/reqwest#44.

This reverts commit 35b07e5, reversing
changes made to b9c20ea.
repi pushed a commit to EmbarkStudios/reqwest that referenced this issue Dec 20, 2019
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

No branches or pull requests

3 participants