Skip to content

Conversation

@ricochet
Copy link
Contributor

Tests called find_available_port() which binds a TcpListener to port 0,
reads the port, then drops the listener.

Later, HttpServer::start() tries to re-bind that same port.
Between the drop and re-bind, another test (running in parallel) can
grab that port.

HttpServer::new() binds the TcpListener eagerly and holds it. The socket
stays open from construction through to start(), which takes ownership
of the already-bound listener. The port is never released, so no other
process or test can steal it. Tests just pass "127.0.0.1:0" to new() and
call addr() to discover the port.

@ricochet ricochet requested a review from a team as a code owner January 28, 2026 00:18
@ricochet ricochet force-pushed the test-listener branch 4 times, most recently from 50a8356 to c96e2f8 Compare January 28, 2026 17:51
Tests called find_available_port() which binds a TcpListener to port 0,
reads the port, then drops the listener.

Later, HttpServer::start() tries to re-bind that same port.
Between the drop and re-bind, another test (running in parallel) can
grab that port.

HttpServer::new() binds the TcpListener eagerly and holds it. The socket
stays open from construction through to start(), which takes ownership
of the already-bound listener. The port is never released, so no other
process or test can steal it. Tests just pass "127.0.0.1:0" to new() and
call addr() to discover the port.

Signed-off-by: Bailey Hayes <bailey@cosmonic.com>
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.

3 participants