Immediately try next connection when one attempt fails and fix possible race conditions (happy eyeballs) #232
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.
This changeset ensures a new connection attempt will be started immediately when one connection attempt fails. This is quite common when connecting on IPv4-only systems where the first IPv6 connection will fail and the next connection attempt should not have to wait 100ms.
The 100ms delay between connection attempts now only triggers when the connection attempt is still pending. Afaict this is not in violation of RFC 8305 and seems to be in line with how other implementations handle this specific situation (https://daniel.haxx.se/blog/2020/03/16/curl-ootw-happy-eyeballs-timeout/, https://www.isc.org/blogs/2011-01-19-multi-homed-server-over-tcp/, curl/curl#2281 and others).
This can easily be reproduced by connecting to
localhost:1
when nothing is listening on this port. Prior to this patch, this would take around ~160ms on my system, after applying this patch it takes around ~50ms. Likewise, connection setup is improved on IPv4-only systems (such as Docker in its default configuration) when the destination is reachable over both IPv6 and IPv4.Additionally, this changeset fixes two subtle bugs when the connector rejects immediately and when DNS resolves with the same IP address multiple times.
Builds on top of #231, #230, #224 and #225