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)

Aperta
#67 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
  1. 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.
  2. 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.
  3. 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
  1. Call net.setDefaultAutoSelectFamilyAttemptTimeout(10000) at startup, or pass autoSelectFamilyAttemptTimeout per connection.
  2. When an upstream connect fails, reply 502 instead 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 ETIMEDOUT comes from internalConnectMultipleTimeout, not from a TCP timeout.
  • In Node v24.9.0 lib/net.js, internalConnectMultiple arms the attempt timer only when current < context.addresses.length - 1.
  • A host with a single address takes a separate path with no short timer.
  • When the timer fires, internalConnectMultipleTimeout closes 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 -4 connects 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 logged attempting to connect exactly 0.250 s before timed 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 fetch of 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's Connection 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 with sfw: ... is not allowed in NODE_OPTIONS.
  • Without the added delay, 4 of 4 fetches had no ETIMEDOUT with --network-family-autoselection-attempt-timeout=10000 set.
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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di SocketDev/sfw-free

Tutte le issue di SocketDev/sfw-free

Issue simili

Altre issue su CLI

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.