Repository navigation
Description
Disclosure: Researched and posted by Claude Fable 5
What version of Bun is running?
1.3.14
What platform is your computer?
Darwin 25.5.0 arm64 (macOS, Apple Silicon)
What steps can reproduce the bug?
Environment: a network that advertises global IPv6 (router announces a prefix, interfaces get 2003:… addresses) but cannot actually route v6 upstream — common with partial ISP/router misconfiguration. curl -6 https://oauth2.googleapis.com/ fails; curl -4 works in 0.1 s.
// bun run repro.js — cold process, first connection
const t = Date.now();
await fetch("https://aiplatform.googleapis.com/", { method: "HEAD" });
console.log(Date.now() - t, "ms");Result: 70 840 ms. (Second request in the same process: 138 ms — pooled.)
This host matters because it resolves to exactly four AAAA records before any A records:
await require("node:dns").promises.lookup("aiplatform.googleapis.com", { all: true })
// [ 4 × family 6, then several × family 4 ] (RFC 3484 order on macOS)Attempting the documented Node escape hatch has no effect on fetch:
require("node:dns").setDefaultResultOrder("ipv4first");
const t = Date.now();
await fetch("https://aiplatform.googleapis.com/", { method: "HEAD" });
console.log(Date.now() - t, "ms"); // 75 709 ms — unchangedSame machine, same host: node -e 'fetch(...)' completes in 1 288 ms (Happy Eyeballs), curl in ~0.1 s.
What is the expected behavior?
Either of:
- Connect attempts interleave address families per RFC 8305 (Happy Eyeballs v2 §4 explicitly requires alternating families in the attempt list), so a batch of dead same-family addresses cannot monopolize all attempts; and/or
dns.setDefaultResultOrder("ipv4first")influences fetch's resolution order.
What do you see instead?
A cold fetch stalls for the full OS connect timeout (~70 s) before succeeding, on any network with advertised-but-unroutable IPv6.
Root cause (from source, main @ 1498d7b)
Reading the source, this appears to be two independent gaps that combine:
-
setDefaultResultOrderis a JS-shim variable that fetch never consults.src/js/node/dns.tsstores the order indefaultResultOrder.value(L89–92) and its only consumer isdns.lookup()option defaulting in the same file (L248, applied L314). fetch resolves through the native path (dns::getaddrinfo→ uSockets), so the setting is structurally invisible to it — same family as Bun not honoringNODE_OPTIONS="--dns-result-order=ipv4first#28817 (NODE_OPTIONS flavor). -
Parallel connect attempts exist but are family-blind.
packages/bun-usockets/src/context.cdefinesCONCURRENT_CONNECTIONS 4(L27); after resolution,start_connections(c, CONCURRENT_CONNECTIONS)(L735) opens attempts to the first fouraddrinfoentries in resolver order — on this host, all four dead IPv6 addresses. Further addresses are only started when an in-flight attempt fails (L773–774), but unroutable v6 doesn't fail — SYNs blackhole, so all four attempts ride the full connect timeout together before the first IPv4 address is ever tried. Hence the constant ~70 s, matching the measurement within a second.
Node avoids this by racing families with a 250 ms fallback delay (autoSelectFamily); RFC 8305 interleaving in start_connections' address list would likely fix this class entirely (also #25619, and the closed #28405 / #28596 which fixed the same disease for bun install and net.createConnection but not fetch).
Additional information
Found while chasing a constant ~70 s/invocation latency in a subprocess that calls Vertex AI — every fresh process paid the stall on its first connection. Happy to test a patch. (Diagnosis and write-up assisted by Claude; measurements are from a real machine and the source references were verified against a local checkout.)
Activity
[-]fetch stalls ~70 s on advertised-but-unroutable IPv6: connect attempts are not family-interleaved (RFC 8305), and dns.setDefaultResultOrder has no effect on fetch[/-][+]`fetch` stalls ~70 s on advertised-but-unroutable IPv6: connect attempts are not family-interleaved (RFC 8305), and `dns.setDefaultResultOrder` has no effect on `fetch`[/+]dns: fix RFC 8305 address-family interleave so blackholed IPv6 doesn'…