Skip to content

Commit

Permalink
usingcurl/connections/happy.md: describe happy eyeballs
Browse files Browse the repository at this point in the history
  • Loading branch information
bagder committed Aug 8, 2024
1 parent 9780da8 commit 11b46f3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
* [Connections](usingcurl/connections/README.md)
* [Name resolve tricks](usingcurl/connections/name.md)
* [Connection timeout](usingcurl/connections/timeout.md)
* [Happy Eyeballs](usingcurl/connections/happy.md)
* [Network interface](usingcurl/connections/interface.md)
* [Local port number](usingcurl/connections/local-port.md)
* [Keep alive](usingcurl/connections/keepalive.md)
Expand Down
1 change: 1 addition & 0 deletions usingcurl/connections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ you might find yourself wanting to tweak the specifics…

* [Name resolve tricks](name.md)
* [Connection timeout](timeout.md)
* [Happy Eyeballs](happy.md)
* [Network interface](interface.md)
* [Local port number](local-port.md)
* [Keep alive](keepalive.md)
44 changes: 44 additions & 0 deletions usingcurl/connections/happy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Happy Eyeballs

When curl is about to connect to a given host, it has a list of addresses to
try. The address list is separated into two lists: one list with IPv4
addresses and one list with IPv6 addresses.

curl starts by initiating a connect attempt to the first address in the IPv6
list. If the connect attempt fails, it moves on to the next address in the
list iterating through them all one by one until one works.

If, after two hundred milliseconds curl still tries to connect to IPv6, it
starts a second series of attempts over IPv4 in parallel. In the same style it
iterates over the list of IPv4 addresses on connect errors. A connection race
if you will.

The first connect that works wins, and all the other attempts are then
discarded.

## HTTP/3 racing

When asked to attempt HTTP/3 (with `--http3`), curl ups the connection racing
game one level.

curl first starts the Happy Eyeballs connect attempt for QUIC as described
above. First it tries IPv6 QUIC and then IPv4 QUIC after a timeout. If there
is no successful QUIC connection within the first two hundred milliseconds (or
no UDP package received at all within half the timeout window, one hundred
milliseconds by default), curl starts a *second* Happy Eyeballs scenario for
TCP - first IPv6 TCP and then IPv4 TCP after the timeout.

The first connect attempt that succeeds out of the up to four parallel ones
that are running, wins. The "losers" are then simply discarded.

## Tweak

The two hundred milliseconds delay is sometimes making your connections slower
than you want to. For example if the host is just silently swallowing the TCP
packets over IPv6 making the timeout always expire. Or vice versa, maybe you
feel you need to allow it a slightly longer time.

For moments and scenarios like that, curl provides the
`--happy-eyeballs-timeout-ms` command line option. It changes the default two
hundred milliseconds to whatever you specify. Setting it to zero makes curl
start the connection attempts at exactly the same time.

0 comments on commit 11b46f3

Please sign in to comment.