cURL / Mailing Lists / curl-library / Single Mail


Re: Happy Eyeballs connection timeout

From: Daniel Stenberg <>
Date: Mon, 5 Oct 2015 00:22:39 +0200 (CEST)

On Thu, 1 Oct 2015, William Ward (wilward) wrote:

> Set the libcurl CURLOPT_CONNECTTIMEOUT_MS = 10000 ( 10 seconds )
> The observed timeout is 5200ms, shorter than expected

I could start out by saying that exactly how to deal with timeouts when there
are multiple IP addresses to try isn't exactly an easy problem.

If you have N entries to try, we don't want to waste the entire timeout time
on the first entry as the next one might work so it would be annoying to
timeout on the first one then. But that also means that you'll not spend the
entire timeout period trying the first which might surprise some users...

> In connect.c, Curl_connecthost method, line 1159, the timeout_ms_per_addr is
> halved if there is more than 1 node in the tempaddr linked list before any
> connection attempt,
> This will be case if there is both an A and AAAA record available for the

IIRC, the intent is then that it'll only spend half the allowed time trying to
connect to the first address before it moves on.

But as the A and AAAA attempts are made in parallel it should only do that for
more than one in the list of the same family.

> Since the IPV6 and IPV4 connections are done in parallel, I'm wondering if
> it is really necessary to half timeout on line 1159, perhaps reducing the
> timeout of the IPv4 attempt by HAPPY_EYEBALLS_TIMEOUT ( 200ms ) would be a
> good approach when there is more than one node in the tempaddr linked list.

I'm not sure what good reducing it with 200ms will do? 200ms is a very short
time to leave for something else when it comes to TCP connections.

> Also I was wondering why the connection timeout is halved again on line 829
> when the first connection fails ? Are there cases other than happy eyeballs
> where there is more than 1 address to attempt and it is appropriate to half
> the timeout ?

Happy eyeballs is just trying A and AAAA in parallel. You can have N number of
A entries (or AAAA entries) without happy eyeballs and then we need to
distribute the allowed time somehow.

Giving up too early is certainly not good. Have you tried to improve the logic
for your tests?

List admin:
Received on 2015-10-05