You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(cli): sandbox forward tests flake when another test claims the released port #4569
I'm the OpenShell 0.1.5 release captain. The rustls security fix (#4568) failed Branch Checks because of an unrelated flaky CLI test, which held up the release fix.
Description
openshell-cli::sandbox_create_lifecycle_integration::sandbox_create_keeps_sandbox_with_forwarding failed on aarch64-linux with:
sandbox create with forward should succeed: × Port 36059 is already in use by another process.
The test reserves a forward port by binding 127.0.0.1:0, reading the port, and dropping the listener. nextest runs tests as concurrent processes, so another test's bind("127.0.0.1:0") can be handed the same ephemeral port before the CLI checks it. Three other forward tests in the file, and the reserve_local_port helper, use the same pattern.
The implementation uses port zero for generic connection failures and retained silent listeners for PostgreSQL handshake/acquisition timeouts. A Linux-only test retains a bound, non-listening socket to verify exact refusal and exclusion of reuse-enabled listeners. This removes the shared connected-pair fixture after self-review reproduced its macOS reuse gap, and removes the added test feature/dependencies. The audit comment records the remaining server/subprocess handoff candidates separately.
Audit of released-port fixtures (continuation of the #5947 failure):
The revised patch uses destination 127.0.0.1:0 for generic connection failures: a listener cannot claim destination port zero. PostgreSQL timeout tests instead retain a listener that never answers the handshake. A separate Linux-only test holds a bound, non-listening socket and checks both exact connection refusal and exclusion of a normal Tokio listener (which enables SO_REUSEADDR).
The connected-pair guard was removed after self-review reproduced a macOS SO_REUSEADDR listener claiming its source port. Removing it also removes all added dev-dependencies and restores the original no-default-features graphs.
Fixed sites:
PostgresStore::unresponsive_url_for_tests and its startup, mutation-lock, and pool-budget callers retain the silent listener through acquisition. The Linux refusal test retains its bound socket.
A container or subprocess binds the released port later.
Network supervisor proxy.rs: dropped UDP socket used as an unreachable DNS server
UDP needs its own strategy; holding a UDP socket changes the expected failure into a timeout.
The original SSH-forward cases already have bounded retries for both preflight port conflicts and fake SSH exit 255 (the latter also tracked in #4797). Unix-domain sockets in temporary directories and fixtures that retain their actual listening sockets were excluded from the TCP race findings.
Validation of the revised patch: focused macOS ARM64 tests and all 14 testkit program checks pass; the silent PostgreSQL startup fixture passes 12 runs across four concurrent processes. Clippy, formatting, Markdown lint, and the no-default-features graph check pass. The Linux-only refusal/performance tests and Windows runtime behavior were not validated locally.
Activity
test(cli): retry forward tests when another process takes the port
test(cli): retry forward tests when another process takes the port (a…
TaylorMutch commentedon Nov 24, 2026
Reopened after #5947 failed its ARM64 Linux Rust test job: https://github.com/ai-openshell/openshell/actions/runs/45467433034/job/138705982778 . The PostgreSQL test
connect_to_a_refusing_server_fails_unavailable_within_the_acquire_timeoutexpected connection refusal but receivedunexpected response from SSLRequest: 0x48; 10,508 of 10,509 tests passed. Its fixture releases an OS-assigned port before connecting, allowing another parallel test to listen there.The implementation uses port zero for generic connection failures and retained silent listeners for PostgreSQL handshake/acquisition timeouts. A Linux-only test retains a bound, non-listening socket to verify exact refusal and exclusion of reuse-enabled listeners. This removes the shared connected-pair fixture after self-review reproduced its macOS reuse gap, and removes the added test feature/dependencies. The audit comment records the remaining server/subprocess handoff candidates separately.
TaylorMutch commentedon Nov 24, 2026
Audit of released-port fixtures (continuation of the #5947 failure):
The revised patch uses destination
127.0.0.1:0for generic connection failures: a listener cannot claim destination port zero. PostgreSQL timeout tests instead retain a listener that never answers the handshake. A separate Linux-only test holds a bound, non-listening socket and checks both exact connection refusal and exclusion of a normal Tokio listener (which enables SO_REUSEADDR).The connected-pair guard was removed after self-review reproduced a macOS SO_REUSEADDR listener claiming its source port. Removing it also removes all added dev-dependencies and restores the original no-default-features graphs.
Fixed sites:
PostgresStore::unresponsive_url_for_testsand its startup, mutation-lock, and pool-budget callers retain the silent listener through acquisition. The Linux refusal test retains its bound socket.Potential remaining handoff races found by the audit (not covered by the refusal fixture):
auth.rs,callback.rs, andoidc_auth.rs:free_loopback_portsandbox_create_lifecycle_integration.rs: the two directspawn_service_forwardcallersreserve_local_portwithout the SSH forward helper's collision retries.lib.rs:reserved_loopback_addressfailed_export_does_not_stop_the_relayhost_server_support::free_portand conformance port forwardinge2e/rustfind_free_port, gateway shell helpers, Python native-endpoint fixture, Kubernetes app-listener port-forwardproxy.rs: dropped UDP socket used as an unreachable DNS serverThe original SSH-forward cases already have bounded retries for both preflight port conflicts and fake SSH exit 255 (the latter also tracked in #4797). Unix-domain sockets in temporary directories and fixtures that retain their actual listening sockets were excluded from the TCP race findings.
Validation of the revised patch: focused macOS ARM64 tests and all 14 testkit program checks pass; the silent PostgreSQL startup fixture passes 12 runs across four concurrent processes. Clippy, formatting, Markdown lint, and the no-default-features graph check pass. The Linux-only refusal/performance tests and Windows runtime behavior were not validated locally.