Skip to content

test(e2e): the port-reservation helpers have no non-Linux test coverage #2787

Done

Description

@yigitdot

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 /proc read failure (ports.rs:167). Both are low value.
  • The explicit Ipv4Addr, SocketAddr and socket2 imports in ports/tests.rs are redundant. use super::* already brings them in from ports.rs:18,21. Only UdpSocket and TcpListener need their own use.
  • No CI job builds on macOS with warnings denied, so a new Linux-only helper added without its #[cfg] brings the macOS cargo-clippy pre-commit failure back while CI stays green.

🤖 Generated with Claude Code

Activity

  1. added
    kind:test
    prio:low
    on Oct 30, 2026
  2. yigitdot commented on Oct 30, 2026

    @yigitdot
    ContributorAuthor

    #2795 covers items 1, 2 and 3b:

    • 1: child_binds_a_reservation and child_rebinds_a_reservation_after_a_restart run on every target now. A mutation check confirmed that on macOS they fail with EADDRINUSE if PortReservation holds its socket.
    • 2: a new test, bind_to_port_zero_never_lands_below_ephemeral_low, makes 1,000 TCP and 1,000 UDP bind(…:0) calls and fails if any port lands below ephemeral_low().
    • 3b: the redundant imports are gone, so no import in ports/tests.rs needs a cfg gate.

    3c is settled without a CI job. No macOS clippy job will be added. The macOS cargo-clippy pre-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 and EPHEMERAL_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 /proc read failure (ports.rs:167) has a test yet.

    🤖 Generated with Claude Code

  3. yigitdot commented on Oct 30, 2026

    @yigitdot
    ContributorAuthor

    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_listen copies the daemon's bind. The helper in crates/e2e/src/ports/tests.rs is a copy of decdn-node's pub(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 own bind_reuseaddr_enables_so_reuseaddr test limits the risk.
    • Off Linux, ephemeral_low() is a hard-coded 49152. test(e2e): run the PortReservation child-bind tests off Linux #2795 tests this value with UDP bind(…:0) calls, but the fixtures still use it as it is. On macOS, ephemeral_low() could read net.inet.ip.portrange.first, as it reads /proc on Linux. The premise would then hold at run time rather than only under test. This is a production change in crates/e2e/src/ports.rs.
    • The EPHEMERAL_PICKS doc understates the test. It says released reservations would be hit "about ten times". The reviewer estimates about 23 on a default Linux range, because an SO_REUSEADDR bind(…: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:128 and the /proc read to ports.rs:171.

    🤖 Generated with Claude Code

  4. thiras commented on Nov 10, 2026

    @thiras
    Contributor

    Status on main (ee1d12d), after #2795:

    • Items 1, 2 and 3b: the child-bind tests run off Linux, and udp_bind_to_port_zero_never_lands_below_ephemeral_low checks the UdpPortClaim premise.
    • 3a: no test yet for the "no free UDP port" and /proc read error paths.
    • Off Linux, ephemeral_low() still returns a fixed 49152 (ports.rs).
    • The EPHEMERAL_PICKS doc still says "ten times" (ports/tests.rs:8).
    • node_style_listen is still a copy of the daemon's bind, not the daemon's own code.
  5. yigitdot commented on Nov 26, 2026

    @yigitdot
    ContributorAuthor

    Status on main (e720fbb), after #2942 (e0455c9):

    • Off Linux, ephemeral_low() reads macOS net.inet.ip.portrange.first (crates/e2e/src/ports.rs) instead of a fixed 49152.
    • The "no free UDP port" error after the pick limit has a test: udp_claim_fails_when_every_pick_is_held (ports/tests.rs).
    • The /proc read failure has no test. Only the parse is tested.
    • The EPHEMERAL_PICKS doc still says "ten times" (ports/tests.rs:8).
    • node_style_listen is still a copy of the daemon bind (ports/tests.rs:29).
  6. moved this from Backlog to Done in deCDNon Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:testprio:low

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions