curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Re: Setting connection timeout per host?

From: Daniel Stenberg via curl-library <>
Date: Sat, 9 Jan 2021 18:00:21 +0100 (CET)

On Sat, 9 Jan 2021, Midnight Wonderer via curl-library wrote:

> Regarding CURLOPT_CONNECTTIMEOUT_MS option, I found out that the timeout set
> is shared between multiple hosts. Not only that, the allotment is weird,
> IMO.

One person's sensible is another person's weird... This is the middle-way:
both sensible and weird.

> If you set the connection timeout to 3 seconds, the first server gets 1.5s
> budget; the second one gets 750ms, the third 375ms, and so on.
> Don't get me wrong; I think splitting into [timeout]/N is equally weird too.
> What I actually expect from the connection timeout is: it should be applied
> per connection.

There's just no way to satisfy every possible request and desire without
overloading libcurl with even more options.

- Users expect the timeout to expire after the given time, so if the host has
N addresses, they still don't want the timeout to be multiplied with N.

- Users expect that just because one out of the N IP addresses is dead, the
timeout shouldn't needlessly expire and leave the user thinking all addresses
are inaccessible.

These two expectations don't work in combination with: "curl should spend the
entire connection timeout-out time trying to connect to the first IP address".
We simply felt a need to compromise a little.

(Once I attended a meeting with lots of HTTP people, where it was suggested
that maybe clients would be better off happy-eyevalling *every* IP address
that is returned - connect to all of them at once and stick only to the one
that connects the fastest... which would also solve this timeout issue!)

> For instance, if I set the timeout to 1s, I expect connection timeouts of 1s
> for each try. This is also the behavior of Nginx when used as a reverse
> proxy.

So what does nginx do when the first IP address just silently drops all TCP
packets? Fail the connection after one second even if there are also 9 working
IP addresses?

  | Commercial curl support up to 24x7 is available!
  | Private help, bug fixes, support, ports, new features
Received on 2021-01-09