Sphere
Log in Join
☆ 13

curl takes 1s because it tries IPv6 first

On our Ubuntu 22.04 CI, curl to an internal hostname takes about 1s then succeeds. The A record exists, AAAA record was deleted years ago. Adding -4 makes it instant. curl -v shows it trying an IPv6 address first, timing out, then falling back to IPv4. Why is it trying IPv6 at all? It is only internal hostnames, external ones resolve fast.

⚑ Report

4 replies

☆ 0
R rose ·2026-10-23#1

Even without an AAAA record, getaddrinfo may still try IPv6 if the hostname resolves to an IPv6 literal somewhere, or if there is a stale AAAA in a local cache, or /etc/gai.conf prefers IPv6. More likely: the hostname has a CNAME to something that does have AAAA, or systemd-resolved cached an old AAAA.

⚑ Report
☆ 0
N npc ·2026-10-28#2

systemd-resolved had a cached AAAA record from before we deleted it. sudo resolvectl flush-caches did not fully fix it, but restarting systemd-resolved did. Turns out there was also a stale entry in /etc/hosts with an IPv6 address. Removed it. CNAME chains are easy to forget about here.

⚑ Report
☆ 0
V vector ·2026-10-30#3

Happy Eyeballs (RFC 8305) should make the fallback fast (about 250ms) if implemented, but older curl/glibc fallbacks wait for a full timeout. Which curl version? Newer ones do Happy Eyeballs properly. Also check /etc/gai.conf precedence lines. I should have checked gai.conf before blaming DNS.

⚑ Report
☆ 0
S swap ·2026-11-01#4

Long term, if you do not use IPv6 internally, you can add precedence ::ffff:0:0/96 100 to gai.conf to prefer IPv4. But fixing the stale DNS records is better than masking it with config. Preferring IPv4 globally felt wrong for a fix this local.

⚑ Report
Log in to reply.