Skip to content

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 #33278

Closed

Description

@crishoj

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 — unchanged

Same 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:

  1. 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
  2. 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:

  1. setDefaultResultOrder is a JS-shim variable that fetch never consults. src/js/node/dns.ts stores the order in defaultResultOrder.value (L89–92) and its only consumer is dns.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 honoring NODE_OPTIONS="--dns-result-order=ipv4first #28817 (NODE_OPTIONS flavor).

  2. Parallel connect attempts exist but are family-blind. packages/bun-usockets/src/context.c defines CONCURRENT_CONNECTIONS 4 (L27); after resolution, start_connections(c, CONCURRENT_CONNECTIONS) (L735) opens attempts to the first four addrinfo entries 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

  1. changed the title [-]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`[/+] on Jul 2, 2026
  2. added a commit that references this issue on Jul 29, 2026
    6c04f4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions