Repository navigation
Description
The review of #2785 found these gaps in crates/e2e/src/ports/tests.rs. They all predate that PR. Mac developers do run this code: NodePorts::new and the anvil-e2e gateway, SDK and sponsord journeys pick their ports through PortReservation and UdpPortClaim. CI runs Rust tests and clippy only on Linux.
1. PortReservation::tcp() is never tested off Linux
Off Linux, cfg!(target_os = "linux").then_some(socket) (crates/e2e/src/ports.rs:71) releases the reservation socket at once. That release is required on macOS: a probe showed that a held, non-listening SO_REUSEADDR socket makes the child's SO_REUSEADDR bind-and-listen fail with EADDRINUSE. If that line changes to always hold the socket, Linux CI and every macOS unit test still pass, but every macOS anvil-e2e journey fails on its admin, metrics and gateway ports.
Proposal: run child_binds_a_held_reservation and held_reservation_survives_a_child_restart on every target, and document what a reservation guarantees on non-Linux. The probe showed both pass on macOS, including the rebind after TIME_WAIT. This also removes most of the #[cfg(target_os = "linux")] gates that #2785 adds: on node_style_listen and the SocketAddr/TcpListener/socket2 imports. Only EPHEMERAL_PICKS stays Linux-only.
2. The non-Linux ephemeral_low() value is never checked against the kernel
Off Linux, ephemeral_low() returns a fixed 49152 (crates/e2e/src/ports.rs:164-166). udp_claim_is_below_the_ephemeral_range compares the claim with ephemeral_low(), the same function the claim is built from, so it cannot catch a wrong value. On a host with a tuned ephemeral range, claims could land inside it and race with bind(…:0).
Proposal: add a portable test that makes many UDP and TCP bind(…:0) calls and asserts that none returns a port below ephemeral_low(). That is the premise UdpPortClaim relies on, and on Linux the same test also checks the /proc read.
3. Smaller items
- Two error paths have no test: the "no free UDP port" error after the pick limit (
ports.rs:124) and the/procread failure (ports.rs:167). Both are low value. - The explicit
Ipv4Addr,SocketAddrand socket2 imports inports/tests.rsare redundant.use super::*already brings them in fromports.rs:18,21. OnlyUdpSocketandTcpListenerneed their ownuse. - No CI job builds on macOS with warnings denied, so a new Linux-only helper added without its
#[cfg]brings the macOScargo-clippypre-commit failure back while CI stays green.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
yigitdot commentedon Oct 30, 2026
#2795 covers items 1, 2 and 3b:
child_binds_a_reservationandchild_rebinds_a_reservation_after_a_restartrun on every target now. A mutation check confirmed that on macOS they fail withEADDRINUSEifPortReservationholds its socket.bind_to_port_zero_never_lands_below_ephemeral_low, makes 1,000 TCP and 1,000 UDPbind(…:0)calls and fails if any port lands belowephemeral_low().ports/tests.rsneeds a cfg gate.3c is settled without a CI job. No macOS clippy job will be added. The macOS
cargo-clippypre-commit hook catches a Linux-only helper that is missing its gate. After #2795, the only Linux-only items in the file are two tests andEPHEMERAL_PICKS.3a stays open, so this issue stays open too. Neither the "no free UDP port" error after the pick limit (
ports.rs:124) nor the/procread failure (ports.rs:167) has a test yet.🤖 Generated with Claude Code
test(e2e): bind UDP only in the ephemeral_low test and correct the po…
yigitdot commentedon Oct 30, 2026
The review of #2795 found three more items outside that PR's scope. They are recorded here so this issue tracks all of them:
node_style_listencopies the daemon's bind. The helper incrates/e2e/src/ports/tests.rsis a copy ofdecdn-node'spub(crate)net::bind_reuseaddr(crates/node/src/net.rs:37-48). If the daemon changes how it binds, the reservation tests still pass. The node crate's ownbind_reuseaddr_enables_so_reuseaddrtest limits the risk.ephemeral_low()is a hard-coded 49152. test(e2e): run the PortReservation child-bind tests off Linux #2795 tests this value with UDPbind(…:0)calls, but the fixtures still use it as it is. On macOS,ephemeral_low()could readnet.inet.ip.portrange.first, as it reads/procon Linux. The premise would then hold at run time rather than only under test. This is a production change incrates/e2e/src/ports.rs.EPHEMERAL_PICKSdoc understates the test. It says released reservations would be hit "about ten times". The reviewer estimates about 23 on a default Linux range, because anSO_REUSEADDRbind(…:0)first searches the odd ports in the lower half of the range, where the reservations also land. So the test is stronger than the doc says. Re-derive the figure on Linux before changing the doc.The line numbers in my earlier comment move by four when #2795 merges: the "no free UDP port" error moves to
ports.rs:128and the/procread toports.rs:171.🤖 Generated with Claude Code
test(e2e): run the PortReservation child-bind tests off Linux (#2795)
thiras commentedon Nov 10, 2026
Status on
main(ee1d12d), after #2795:udp_bind_to_port_zero_never_lands_below_ephemeral_lowchecks theUdpPortClaimpremise./procread error paths.ephemeral_low()still returns a fixed 49152 (ports.rs).EPHEMERAL_PICKSdoc still says "ten times" (ports/tests.rs:8).node_style_listenis still a copy of the daemon's bind, not the daemon's own code.fix(e2e): read the macOS ephemeral port range for UDP claims (#2942)
yigitdot commentedon Nov 26, 2026
Status on
main(e720fbb), after #2942 (e0455c9):ephemeral_low()reads macOSnet.inet.ip.portrange.first(crates/e2e/src/ports.rs) instead of a fixed 49152.udp_claim_fails_when_every_pick_is_held(ports/tests.rs)./procread failure has no test. Only the parse is tested.EPHEMERAL_PICKSdoc still says "ten times" (ports/tests.rs:8).node_style_listenis still a copy of the daemon bind (ports/tests.rs:29).