Skip to content

test(tests): bind the test servers to a port the OS assigns - #198

Draft
greenhat616 wants to merge 1 commit into
feat/hardening-33-if-rangefrom
test/hardening-34-port-race
Draft

greenhat616 wants to merge 1 commit into
feat/hardening-33-if-rangefrom
test/hardening-34-port-race

Conversation

@greenhat616

Copy link
Copy Markdown
Owner

Test infrastructure for the download strategy hardening stack. It is stacked on #197, which is its base branch. The design note is in §14.24.

Why

The test servers in crates/bolt-load-tests/src/adapter/http_server.rs called portpicker::pick_unused_port() and then TcpListener::bind on that port. A parallel test could take the port in between, and on Windows the bind then failed with os error 10048. Before this fix, 2 of 40 if_range runs failed this way. Earlier full runs on #197 hit it as well.

What

  • bind_local(): a new private helper binds 127.0.0.1:0 and reads the port from local_addr(). The same listener is handed to axum::serve. It replaces both pick-then-bind sites, and the public helper signatures are unchanged.
  • portpicker is dropped. Nothing else used it. The lock loses portpicker, rand 0.8.8, rand_chacha 0.3.1 and rand_core 0.6.4. Nothing was added or upgraded, and --locked passes.
  • The crate README now describes the binding.
  • No other sites: the workspace has no other pick-then-bind or fixed-port server. tests/empty_body.rs and bolt-load-adapter/tests/body_decoding.rs already bind port 0.

Verification

  • if_range: 40 runs of the test binary, 0 failures.
  • resource_changed: 40 runs, 0 failures.
  • Full workspace, all features: 27 suites, 782 passed, with no 10048.
  • Full workspace, default features: 27 suites, 714 passed, with no 10048.

Review

Reviewed with /ccg:review, using the codex backend only (a single-model review).

PASS (98/100). It confirmed three points:

  • The bound listener is the one served, so the race is gone.
  • The pruned lock is consistent and uses Cargo's canonical form.
  • No other pick-then-bind site is left.

Its Minor, the README still naming portpicker, is fixed. Its suggestion is left as is: the adapters' unit tests build localhost URLs, and localhost may resolve to ::1 first. That predates this PR, and this change keeps the same bind address.

Checks

All on +nightly-2026-11-06, with --no-fail-fast. Clippy allows unnecessary_lazy_evaluations until #183 merges.

  • cargo fmt --all -- --check.
  • The 4 clippy configs with -D warnings.
  • Both workspace test runs, as above.
  • cargo doc: the same 18 errors as its base.

The test servers picked a free port with portpicker and bound it a
moment later, so a server started in between by a parallel test could
take it, and on Windows the bind then failed with os error 10048. They
now bind 127.0.0.1:0 and read the port from the listener. portpicker
has no other users and is dropped, along with the rand 0.8 packages
only it pulled in.
@greenhat616
greenhat616 force-pushed the test/hardening-34-port-race branch from d1dd983 to 235f0f7 Compare November 13, 2026 22:26
@greenhat616
greenhat616 removed this pull request from stack #190 November 13, 2026 22:28
@greenhat616
greenhat616 added this pull request to stack #215 November 13, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant