Learning center

Connect timeouts when a name has IPv6 addresses the host cannot reach

When a name returns AAAA records and the host has an IPv6 address but no working IPv6 path, clients that try IPv6 first wait for it to fail before trying IPv4. Some clients race the two families and lose only a fraction of a second; others try IPv6 until the connect timeout and then give up. Compare curl -4 with curl -6 from the failing host, and read its IPv6 routes, before you blame the dependency.

The symptom#

Calls to a dependency take seconds longer than they should, or fail with connect timeouts, from some hosts only:

  • curl https://api.example.com hangs for a while and then succeeds; curl -4 is instant.
  • The dependency recently added AAAA records, or moved to a provider or load balancer that publishes them.
  • The failing hosts are in a subnet or cluster where IPv6 was half set up: addresses assigned, no default route, or a firewall that drops IPv6.

The address the client connects to depends on the sorted list the resolver returned and on the client's connection strategy, so two services on the same host can behave differently.

Why IPv6 goes first#

glibc's getaddrinfo sorts its results with the RFC 3484 rules, whose default precedence table ranks IPv6 (::/0, precedence 40) above IPv4-mapped addresses (::ffff:0:0/96, precedence 10). RFC 6724, which replaced RFC 3484, keeps IPv6 ahead of IPv4 in its default policy table. A client that walks the list in order tries the IPv6 addresses first. gai.conf(5) · RFC 6724

With its default hints, getaddrinfo uses AI_ADDRCONFIG, which returns IPv6 addresses only if the local system has at least one IPv6 address configured, not counting loopback. A host with an IPv6 address and no IPv6 route still gets AAAA results. getaddrinfo(3)

What happens next depends on the client:

ClientBehavior
Happy Eyeballs (RFC 8305)Starts IPv6, then IPv4 after a short delay; recommended 250 ms
curlGives IPv6 a 200 ms head start by default
Go net.DialerStarts the other family after FallbackDelay, 300 ms by default
Node.js netautoSelectFamily on by default since v20
JavaPrefers IPv4 unless java.net.preferIPv6Addresses is set
Plain sequential connectTries each address in order, each up to the connect timeout

RFC 8305 · curl manual · Go net.Dialer · Node.js net · Java networking properties

A client with Happy Eyeballs usually hides the broken IPv6 path at a small cost. A sequential client with a 10-second connect timeout and two AAAA records spends 20 seconds before it reaches the first IPv4 address, which in practice means the request times out first.

Observe without changing anything#

From the failing host or container, see what the name returns and in which order the system sorts it. getent ahosts prints the addresses in the order getaddrinfo returns them. getent(1)

dig +short NAME A
dig +short NAME AAAA
getent ahosts NAME

Then read the host's IPv6 configuration, and ask the kernel which route it would use for one of the AAAA addresses. ip-route(8)

ip -6 addr show
ip -6 route show
ip route get 2001:db8:10::25

Finally, time the connection per family. -4 and -6 restrict curl to one family, and --connect-timeout bounds the connection phase. curl manual

curl -4 -sv -o /dev/null --connect-timeout 5 -w '%{time_connect}\n' https://NAME/
curl -6 -sv -o /dev/null --connect-timeout 5 -w '%{time_connect}\n' https://NAME/

Read the result#

curl -6curl -4IPv6 routePoints to
Times outFastNone for the addressHost has IPv6 addresses but no route; clients that prefer IPv6 stall
Times outFastPresentIPv6 blocked or broken on the path or at the dependency
FastFastPresentNot IPv6; look at the client's own timeouts or the dependency
Times outTimes outAnyNot an address-family problem; see refused vs timeout

If ip route get returns an error such as network unreachable, the client should fail fast rather than time out, and a quick failure followed by IPv4 is harmless. Long stalls come from a route that exists, such as a default route, where packets then disappear. Connection refused or timeout

A worked example#

This example is illustrative. On Monday, the payments provider adds AAAA records for api.payments.example.com: 2001:db8:10::25 and 2001:db8:10::26, beside 203.0.113.25. The checkout service runs on hosts in a dual-stack subnet whose route table has an IPv6 default route to a gateway that the network team has not finished configuring.

From a checkout host:

CheckResult
getent ahoststhe two IPv6 addresses first, then 203.0.113.25
ip route get 2001:db8:10::25via the IPv6 default route
curl -6 --connect-timeout 5timed out after 5 s
curl -4 --connect-timeout 5connected in 22 ms

The checkout service uses an HTTP client that connects to addresses in order with a 10-second connect timeout. Every request now tries both IPv6 addresses before IPv4 and hits the request deadline first. The orders service on the same hosts is written in Go and sees only an extra 300 ms per new connection. The provider is healthy over IPv4 and the path is the problem.

In a second case, curl -6 connects in 25 ms and curl -4 in 21 ms, and the service still times out. IPv6 is not the cause; compare with the dependency's own latency next. Client or server latency

Limits#

curl runs its own connection logic. A successful curl -4 says the IPv4 path works, not how your client orders and retries addresses; read the client library's documentation for its strategy and timeouts.

The sort order is configurable. In /etc/gai.conf, a precedence line that ranks ::ffff:0:0/96 above ::/0 makes glibc sort IPv4 first, but any single precedence line replaces the whole default table, so copy the defaults you keep. That is a host change, not a diagnosis. Other runtimes, such as Go's pure resolver and Node.js with its default verbatim order, apply their own ordering. Node.js dns result order

For lookups that fail outright rather than connect slowly, see NXDOMAIN, SERVFAIL or no answer. For the method across dependency layers, see runtime dependency failures.

Questions#

Why does curl hang before connecting when the site works?

The name has AAAA records and your host has an IPv6 address but no working IPv6 path. curl tries IPv6 first and falls back to IPv4 after its Happy Eyeballs delay or the connect attempt fails. Compare curl -4 and curl -6 to confirm.

Does removing the AAAA lookup fix it?

It hides it. glibc's no-aaaa option in resolv.conf (since glibc 2.36) suppresses AAAA queries, and an IPv4 preference in gai.conf reorders results. Fixing or removing the host's broken IPv6 route addresses the cause.

What is Happy Eyeballs?

An algorithm, specified in RFC 8305, that starts a connection over IPv6 and, if it has not succeeded after a short delay, starts one over IPv4 in parallel, keeping whichever connects first. It makes a broken IPv6 path cost milliseconds instead of a full timeout.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading