Upstream connect aborts after 250 ms when the host has an unreachable IPv6 address, and the client gets an empty reply (cargo builds fail intermittently)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 52/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- node.js
- Ambito
- cli, networking
Direzione di ricerca
Start at the CONNECT request boundary and the startup or upstream connection setup, then reproduce with the tc delay and sfw cargo fetch. Check how an unreachable IPv6 address and a slow IPv4 connection are handled, and how client responses are formed after an upstream failure. Done means the delayed crates.io reproduction no longer produces an empty reply or premature 250 ms abort.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Disclosure: this was written with Claude Opus 5.5
Env: sfw-free v1.15.2 and v1.15.3 (linux-x64, Node v24.9.0), WSL2 with NAT networking (no IPv6 route), cargo 1.98.1.
sfw cargo fetch fails intermittently with [52] Empty reply from server. sfw logs:
Error caught at boundary "CONNECT request"
AggregateError
> Error connect ETIMEDOUT 199.232.66.137:443 [... Timeout.internalConnectMultipleTimeout (node:net:1737:38) ...]
> Error connect ENETUNREACH 2a04:4e42:50::649:443
Repro (fails every time)
Add 300 ms of delay to crates.io's IPv4 address only:
sudo tc qdisc replace dev eth0 root handle 1: prio bands 4
sudo tc qdisc add dev eth0 parent 1:4 handle 40: netem delay 300ms
sudo tc filter add dev eth0 parent 1: protocol ip prio 1 u32 match ip dst 199.232.66.137/32 flowid 1:4
sfw cargo fetch # in a project depending on e.g. cargo-deny, with an empty CARGO_HOME
# undo: sudo tc qdisc del dev eth0 root
| Result | |
|---|---|
Direct curl -4 |
Connects in 0.34 s |
| sfw v1.15.2 / v1.15.3 | 4 of 4 runs fail in under 1 s, on the first request (config.json) |
Same, with NODE_OPTIONS=--network-family-autoselection-attempt-timeout=10000 |
2 of 2 succeed |
Cause
- The 250 ms timer. Node's happy-eyeballs timer gives each connection attempt 250 ms whenever another address is left to try. crates.io's AAAA record is unreachable here, but its existence is what arms the timer on the IPv4 attempt.
- Lost packets. About 0.3% of connects lose a SYN and need the kernel's 1 s retransmit. sfw makes about 350 upstream connects per fetch, so most fetches hit at least one of these connections, and the timer cuts it off.
- The client gets no answer. sfw closes the client's tunnel without responding. On a reused connection, curl silently retries. On a new connection, the client gets error 52, which cargo does not retry, so the build fails.
Suggested fixes
- Call
net.setDefaultAutoSelectFamilyAttemptTimeout(10000)at startup, or passautoSelectFamilyAttemptTimeoutper connection. - When an upstream connect fails, reply
502instead of closing the tunnel. Clients retry 5xx responses but not an empty reply.
Possibly related: #37 (same error with pnpm, but hangs rather than fails).
Evidence (measurements and source references behind each claim)
The timer, from Node's source
- The
ETIMEDOUTcomes frominternalConnectMultipleTimeout, not from a TCP timeout. - In Node v24.9.0
lib/net.js,internalConnectMultiplearms the attempt timer only whencurrent < context.addresses.length - 1. - A host with a single address takes a separate path with no short timer.
- When the timer fires,
internalConnectMultipleTimeoutcloses the in-flight handle rather than racing it. That departs from RFC 8305 §5; see nodejs/node#48145 (open) and nodejs/node#54359.
Lost SYNs are ordinary, not caused by sfw
- 3000 direct
curl -4connects to static.crates.io, 8 in parallel, with no sfw and no added delay:- Median 43 ms.
- 10 (0.33%) took more than 250 ms, and 6 of those landed at 1.04–1.08 s, which is the SYN retransmit.
- With every CPU core saturated: 0.37%, so local load does not matter.
The timer is not firing late
- With
NODE_DEBUG=net, each failing attempt loggedattempting to connectexactly 0.250 s beforetimed out, with no completion in between. - Neighbouring connects to the same IP completed in 30–60 ms.
- sfw's log never went quiet for more than about 0.34 s, so this is not event-loop lag.
Exposure
- sfw made about 350 upstream connects per
cargo fetchof about 170 packages, roughly one per request. - Without the added delay, 8 of 10 fetches logged at least one ETIMEDOUT, and 4 of those 10 failed outright.
Harmless vs fatal
- Harmless. With
CARGO_HTTP_DEBUG=true, each sfw timeout (3 of 3 in one run) was followed within 1 ms by curl'sConnection died, retrying a fresh connect, and the download continued. - Fatal. cargo's
maybe_spurious(src/util/network/retry.rs) does not treat curl error 52 as retryable. In the delayed repro, the first request fails and cargo exits within a second, with no retry.
Short blips become failures
- In one v1.15.3 run with no added delay, a network blip of about 1.5 s produced 10 consecutive aborted connects, each cut off at 250 ms, and the fetch failed after 5 s.
- A normal TCP client would have ridden out that blip on its SYN retransmit.
Workaround
- sfw honours
NODE_OPTIONS: an invalid flag is rejected withsfw: ... is not allowed in NODE_OPTIONS. - Without the added delay, 4 of 4 fetches had no ETIMEDOUT with
--network-family-autoselection-attempt-timeout=10000set.
Likely wider impact
- Comments on nodejs/node#48145 report the same Node failure on WSL2 with no IPv6 route, and on links where the RTT alone is over 250 ms (Australia to the EU).
- Based on the delayed repro, sfw users on such links would presumably fail on every run. That has not been tested on a real long-distance link.
- Lingua principale
- Nessun dato sulla lingua
- Stelle
- 271
- Fork
- 8
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di SocketDev/sfw-free
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 87/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Tutte le issue di SocketDev/sfw-free
Issue simili
-
manually bump balena-preload to ^19.0.6Forse già presa @shaunmulligan l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 66/100
balena-io/balena-cli#3200 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
[Bug] `bili -c <name> sessions/storage/export` 无视配置文件 — 静默用默认会话目录 | config flag ignored by store lanesForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
ranxianglei/billion-context#7858 ·
I maintainer di solito rispondono entro 1 giorno
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Forse già presa @iliqiliev l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
ajeetdsouza/zoxide#1381 ·
I maintainer di solito rispondono entro 5 giorni
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
MakazhanAlpamys/Soup#3415 ·
I maintainer di solito rispondono entro 1 giorno