feat(client): add per IP address connection timeout #1958
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It has previously been recommended to apply timeouts externally to hyper. The
hyper-timeout crate uses a special connector to apply read and write timeouts
but the connection timeout is still external.
This approach has one major drawback that only an implementation within hyper
can provide. If the requested hostname resolves to multiple IP addresses, hyper
internally tries to connect to each one in turn. If one of them doesn't respond
at all then it hangs until the OS-level timeout kicks in. This defaults to 127
seconds on Linux due to
tcp_syn_retries
being 6. hyper-timeout wraps around allthe connection attempts rather than each one individually so setting that
timeout to something shorter means that it will give up before trying the
second address. You could reduce
tcp_syn_retries
but this is kernel-wide sothis is far from ideal.
Therefore add a
set_connect_timeout
function toHttpConnector
. It defaults toNone
, preserving the earlier behaviour.Closes #1234
I'm thinking a DNS timeout would also be a good idea so I'm working on that too. hyper-timeout's connect timeout covers that part of the process. It's arguably less crucial though. The default DNS timeout with glibc is 5 seconds each for 2 tries, which isn't as bad as 127 seconds, and reducing this system-wide has less of an impact than reducing
tcp_syn_retries
. Please let me know if you want that work in this PR or a new one.I need this backported to 0.12 and I'm hoping you'll accept a PR for that when it's ready.
I'm still relatively new to Rust so please go easy on me! 馃懚