From 7e76f7bea68aa074f1e13ea9b64382321943d4d1 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Wed, 28 Oct 2026 01:33:24 +0100 Subject: [PATCH 1/2] test(hub): a closed port stays bound, so no other process answers on it Seen on macOS: no_daemon_is_a_503_and_a_start_under_way_says_so got a 502 from whatever took the port the test had let go of. Co-Authored-By: Claude Opus 5.5 --- crates/devstack-hub/src/lib.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index a483c757..60d950a5 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -3548,12 +3548,15 @@ mod daemon_send_tests { } /// A port nothing listens on. + /// A port nothing answers on, for the rest of the test run: bound but + /// not listening, so no other process takes it meanwhile (a port only + /// let go of may serve something else a moment later). fn closed() -> u16 { - std::net::TcpListener::bind(("127.0.0.1", 0)) - .unwrap() - .local_addr() - .unwrap() - .port() + let sock = tokio::net::TcpSocket::new_v4().unwrap(); + sock.bind(([127, 0, 0, 1], 0).into()).unwrap(); + let port = sock.local_addr().unwrap().port(); + std::mem::forget(sock); + port } fn serves(port: u16) -> DaemonNow { From 4c436aed994062b246d23801d1be1e29c8e86abe Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Wed, 28 Oct 2026 01:42:55 +0100 Subject: [PATCH 2/2] test(hub): the closed port is a privileged one; macOS lets a bound, unlistened one time out Co-Authored-By: Claude Opus 5.5 --- crates/devstack-hub/src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index 60d950a5..d255ff90 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -3548,15 +3548,12 @@ mod daemon_send_tests { } /// A port nothing listens on. - /// A port nothing answers on, for the rest of the test run: bound but - /// not listening, so no other process takes it meanwhile (a port only - /// let go of may serve something else a moment later). + /// A port nothing answers on: a privileged one, which no test (nor any + /// unprivileged process) can listen on. A port bound and let go of may + /// serve another test's listener a moment later (seen on macOS), and one + /// bound without listening is not refused there but left to time out. fn closed() -> u16 { - let sock = tokio::net::TcpSocket::new_v4().unwrap(); - sock.bind(([127, 0, 0, 1], 0).into()).unwrap(); - let port = sock.local_addr().unwrap().port(); - std::mem::forget(sock); - port + 1 } fn serves(port: u16) -> DaemonNow {