net: Happy Eyeballs cancels every candidate when TCP RTT exceeds the 250ms attempt timeout — fetch fails with an empty-message ETIMEDOUT against healthy hosts
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 45/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, node.js
- 領域
- backend, networking
研究方向
Start by tracing Node's network family autoselection path and how --network-family-autoselection-attempt-timeout is applied to candidate connections; the issue does not name source files or tests. Reproduce with the supplied script and compare default behavior with --no-network-family-autoselection and a longer attempt timeout. Done means a healthy connection succeeds when its RTT exceeds the default attempt timeout, with regression coverage for the timeout behavior and useful error reporting.
由索引模型根據 Issue 內容生成。
描述
Summary
With Happy Eyeballs on (the default since v20), fetch() / https.get() fails outright against any destination whose TCP connect RTT exceeds the attempt timeout, because the same value is used both as the stagger interval between candidates and as the deadline that cancels each candidate. If RTT > attemptTimeout, every candidate is cancelled before its own SYN/ACK can arrive — including the last one — so the algorithm cannot succeed at all, while connecting without Happy Eyeballs succeeds on the first address.
Measured on v24.22.1 / darwin-arm64 against public hosts. curl and /usr/bin/python3 (SecureTransport) on the same machine at the same second succeed every time; Node is the only client that fails.
Reproduction (no accounts, no setup)
// repro.mjs
import net from 'node:net';
import dns from 'node:dns/promises';
const host = process.argv[2] ?? 'docker.io';
const { address } = await dns.lookup(host, { verbatim: true });
const t0 = Date.now();
const s = net.connect({ host: address, port: 443, family: 4 }); // Happy Eyeballs bypassed: explicit IP
s.on('connect', () => {
console.log(`tcp connect to one IP directly : OK in ${Date.now() - t0} ms`);
s.destroy();
const t1 = Date.now();
fetch(`https://${host}/`)
.then((r) => console.log(`fetch(https://${host}/) : ${r.status} in ${Date.now() - t1} ms`))
.catch((e) => console.log(`fetch(https://${host}/) : FAILED ${e.message}`
+ ` | cause=${e.cause?.code} message="${e.cause?.message}"`
+ ` | cause.errors=${e.cause?.errors?.length}`
+ ` (${e.cause?.errors?.[0]?.code} ${e.cause?.errors?.[0]?.address}) in ${Date.now() - t1} ms`));
});
$ node repro.mjs docker.io
tcp connect to one IP directly : OK in 384 ms
fetch(https://docker.io/) : FAILED fetch failed | cause=ETIMEDOUT message="" | cause.errors=6 | ETIMEDOUT 2600:9000:...:443 in 2798 ms
$ node --no-network-family-autoselection repro.mjs docker.io
tcp connect to one IP directly : OK in 386 ms
fetch(https://docker.io/) : 302 in 1255 ms
The failure is not a property of the destination. Run the same command twice a minute apart and the outcome tracks the current RTT across the 250 ms line:
| target | measured TCP RTT | fetch() at default budget |
|---|---|---|
docker.io |
384, 386 ms | FAIL, FAIL (2/2) |
docker.io |
255, 263 ms | 302, 302 |
quay.io |
369, 388 ms | FAIL, FAIL (2/2) |
quay.io |
237, 265 ms | 200, 200 |
arxiv.org (A-only edge, 4 ms) |
4 ms | 200 (never affected) |
Budget sweep, one variable
Same host, same minute, only --network-family-autoselection-attempt-timeout changes (RTT sampled in the same run):
| budget | RTT sample | result |
|---|---|---|
| 250 (default) | 465 ms | FAIL |
| 250 (default) | 365 ms | FAIL |
| 300 | 368 ms | FAIL |
| 350 | 457 ms | 200 in 2970 ms |
| 350 | 349 ms | FAIL |
| 400 | 372 ms | 200 in 2178 ms |
| 500 | 383, 362 ms | 200, 200 |
| 600 | 389 ms | 200 |
The knee sits exactly at the measured RTT. Note the successful marginal runs take ~2.1–3.0 s — i.e. the winner is the 6th–9th candidate, which is what you get when candidates are launched one attemptTimeout apart and only the last ones are still alive when RTT ≈ budget.
The reported error actively misleads
https.get() rejects with the AggregateError itself (no cause); fetch() wraps it in TypeError: fetch failed:
{ "ctor": "AggregateError", "name": "AggregateError", "message": "", "code": "ETIMEDOUT",
"hasCause": false, "nErrors": 18 }
tally: {"ETIMEDOUT@v4": 9, "EHOSTUNREACH@v6": 9}
sample: {"message": "connect ETIMEDOUT 221.194.164.123:443", "code": "ETIMEDOUT",
"address": "221.194.164.123", "port": 443, "syscall": "connect"}
keys: ["errno","code","syscall","address","port"]
Three problems for anyone debugging this in production:
err.messageis the empty string at the top level — log lines that printerr.messageprint nothing.- Every v4 sub-error says
connect ETIMEDOUT <ip>:443, yet a plainnet.connectto that exact IP completes in ~370 ms. The addresses were never given a chance to finish; they were cancelled at 250 ms. Reporting them asETIMEDOUTsends people hunting for a firewall/blackhole that isn't there (I did — see below). - Nothing in the error mentions the attempt timeout, the number of candidates tried, or that
--no-network-family-autoselectionwould have worked.ECONNREFUSED/EHOSTUNREACHper candidate is fine, but "we cancelled all of them because the budget expired" is a distinct, actionable cause.
What I ruled out first (so you don't have to)
On the same machine, same second: curl 8.7.1 200 · system python3 urllib 200 · openssl s_client handshake OK · Node against pypi/npm/github/google/eastmoney all 200 · 9 v4 addresses in parallel 9/9 OK · tls.connect to each IP individually + hand-written HTTP request 10/10 200 OK. net.setDefaultAutoSelectFamily(false) fixes it. So it is not the network, the certificate, TLS version, ALPN, UA, rate limiting, or the post-quantum ClientHello.
Expected behaviour
Fall back to a working address instead of failing the whole attempt. Options that would each fix my case, in rough order of preference:
- Once all candidates have been cancelled without a completed handshake, retry at least one round without the per-candidate cancellation (curl/SecureTransport effectively do this and never fail here). Or: treat
attemptTimeoutonly as the stagger delay, and let an in-flight candidate live until the socket-level timeout. - Raise the default. RFC 8305's 250 ms default assumes intra-domain reachability; the public internet from many networks is routinely 250–500 ms, which makes the default configuration strictly worse than disabling Happy Eyeballs.
- Make the failure self-describing: non-empty message, and a cause that says "all N candidates exceeded the X ms attempt timeout (last RTT-class: v4/v6)".
Environment / workarounds in use
Node v24.22.1, darwin-arm64, macOS 15, no IPv6 egress on the host. We unblocked production with NODE_OPTIONS=--network-family-autoselection-attempt-timeout=1000 (verified: 8/8 previously-failing call sites now 200, and RTT to unrelated hosts unchanged at 32–192 ms, so the raised budget costs nothing when addresses are healthy). --no-network-family-autoselection also works but gives up fast-fail for genuinely dual-stacked hosts.
Related
- #59738 — "TCP connection timeout in https appears to be just 300ms, causing dropped connections for distant servers" — same symptom, closed as NOT_PLANNED/stale; its reporter also saw it on distant servers only. Worth reopening given it makes the default config fail on healthy destinations.
- #54359 — "Happy eyeballs implementation times out prematurely" (closed COMPLETED)
- #48145 — "Implement parallel Happy Eyeballs as described in RFC 8305" (open) — if #48145 lands with RFC-correct connection timeout semantics (a timer per candidate, independent of the resolution/head-request delays), it likely subsumes this.
- 主要語言
- JavaScript
- 星號
- 124k
- 分支
- 38k
- 平均合併
- 4 天 2 小時
- 30 天內合併 PR
- 266
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 69/100
維護者通常 1 天內回覆
-
fs: document readStream.start and readStream.end可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
doc: document the Buffer.prototype.*Slice() methods可能已有人在做 @AyushCipher 今天認領。 未關閉doc
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 1 天內回覆
-
`styleText` fast path bypasses `options` and `options.validateStream` validation可能已有人在做 @GBra-4-669 於 8 天前認領。 未關閉util
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
riscv64
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
相似的 Issue
-
bug triage needed
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 2 天內回覆
-
resource-submission validation-passed
難度 1/5 1 小時以內 新手友好度 82/100
hesreallyhim/awesome-claude-code#3773 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 73/100
tabatkins/railroad-diagrams#129 ·
-
web: api() turns a null or object-valued error body into a TypeError or "[object Object]" and loses the status可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉bug
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆