Repository navigation
Description
Summary
The anvil e2e fixtures pick loopback ports with free_ports() / free_port() (crates/e2e/src/lib.rs). These bind N ephemeral 127.0.0.1 ports, read the numbers, and drop the listeners. The spawned process (decdn-node, anvil, decdn gateway, decdn dashboard) binds the number later. The function's own docs admit the TOCTOU.
Nextest runs the anvil e2e journeys as parallel processes. The kernel's ephemeral range also serves outbound source ports and every bind(…:0) on the box. So another process can get a released port before the child binds it, and the child fails at bring-up.
Observed locally under load:
g_node_04_blacklist_compliance::regional_blacklist_scope:
failed to bind admin listener: admin bind 127.0.0.1:42515 failed: Address already in use (os error 98)
cli_bundle_pull_range_dedup::cli_bundle_pull_pays_exactly_a_scattered_complement:
metrics port already in use
#2727 lists the same race (candidate 2) for NodeFixture::restart(), which respawns the daemon on the same ports after a SIGKILL. Nothing holds those ports between the kill and the respawn.
Two more gaps in the same code:
- The QUIC
bind_portis a UDP port, butfree_ports()reserves a TCP port. Nothing reserves the UDP number at all. - The gateway e2e journeys (
gateway_*.rs) and thedecdn-nodein-process anvil tests (anvil_bringup_shutdown_e2e.rs,anvil_settlement_e2e.rs) each carry their own copy of the same release-then-bindfree_port().
Measured
On Linux 6.17, with 64 ports picked and released the free_ports way, 20 000 later bind(127.0.0.1:0) calls landed on one of those 64 ports 95 times.
Fix direction
Remove the race by construction rather than by retry:
anvilaccepts--port 0and printsListening on 127.0.0.1:<port>. Let it bind port 0 and read the port back.- Hold a TCP port reservation for the life of the child. A socket bound with
SO_REUSEADDRbut never put in the listening state is never handed out by the kernel forbind(…:0)or as aconnect()source port. A child that binds the same address explicitly withSO_REUSEADDRstill succeeds.decdn-node's admin and metrics listeners (net::bind_reuseaddr), tokio'sTcpListener::bind(the gateway and the dashboard) andanvilall set it. - iroh binds its UDP socket without
SO_REUSEADDR, so a held UDP socket would block the daemon. Pick the QUIC port below the kernel's ephemeral range instead, where the kernel never hands a port out, and claim the number across parallel fixtures with a TCP lock socket on the same number.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
test(e2e): hold every fixture port until its child binds it
test(e2e): hold every fixture port until its child binds it (#2731)