Skip to content

Commit 7295034

Browse files
committed
libstore: Raise default connect-timeout to 15 secs
This allows the weird network or DNS server fallback mechanism inside glibc to work, and prevents a "Resolving timed out after 5000 milliseconds" error. Read on for details. The DNS request stuff (dns-hosts) in glibc uses this fallback procedure to minimize network RTT in the ideal case while dealing with ill-behaving networks and DNS servers gracefully (see resolv.conf(5)): - Use sendmmsg() to send UDP DNS requests for IPv4 and IPv6 in parallel - If that times out (meaning that none or only one of the responses have been received), send the requests one by one, waiting for the response before sending the next request ("single-request") - If that still times out, try to use a different socket (hence different address) for each request ("single-request-reopen") The default timeout inside glibc is 5 seconds. Therefore, setting connect-timeout, and therefore CURLOPT_CONNECTTIMEOUT to 5 seconds prevents the single-request fallback, and setting it to even 10 seconds prevents the single-request-reopen fallback as well. The fallback decision is saved by glibc, but only thread-locally, and libcurl starts a new thread for getaddrinfo() for each connection. Therefore for every connection the fallback starts from sendmmsg() all over again. And since these are considered to have timed out by libcurl, even though getaddrinfo() might return a successful result, it is not cached in libcurl. While a user could tweak these with resolv.conf(5) options (e.g. using networking.resolvconf.extraOptions in NixOS), and indeed that is probably needed to avoid annoying delays, it still means that the default connect-timeout of 5 is too low. Raise it to give fallback a chance.
1 parent 465d627 commit 7295034

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/libstore/include/nix/store/filetransfer.hh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,17 @@ struct FileTransferSettings : Config
3131
)",
3232
{"binary-caches-parallel-connections"}};
3333

34+
/* Do not set this too low. On glibc, getaddrinfo() contains fallback code
35+
paths that deal with ill-behaved DNS servers. Setting this too low
36+
prevents some fallbacks from occurring.
37+
38+
See description of options timeout, single-request, single-request-reopen
39+
in resolv.conf(5). Also see https://github.com/NixOS/nix/pull/13985 for
40+
details on the interaction between getaddrinfo(3) behavior and libcurl
41+
CURLOPT_CONNECTTIMEOUT. */
3442
Setting<unsigned long> connectTimeout{
3543
this,
36-
5,
44+
15,
3745
"connect-timeout",
3846
R"(
3947
The timeout (in seconds) for establishing connections in the

0 commit comments

Comments
 (0)