Repository navigation
MCP HTTP integration test: let the server bind its own port - #11777
Merged
Merged
Conversation
_free_port bound port 0, closed the socket and passed the number to the server process to bind later. Another xdist worker could take the port in between, and the server died with address already in use (seen on the l-r shard of #11766). Worse, the readiness probe could then connect to whichever process now held the port. The server now binds port 0 itself, keeps the socket and reports the port before serving. The new test makes every port this process is handed by the OS one that is already listening; it fails on the old harness and passes here.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
shaojun
pushed a commit
to shaojun/unsloth
that referenced
this pull request
Sep 29, 2026
…i#11777) _free_port bound port 0, closed the socket and passed the number to the server process to bind later. Another xdist worker could take the port in between, and the server died with address already in use (seen on the l-r shard of unslothai#11766). Worse, the readiness probe could then connect to whichever process now held the port. The server now binds port 0 itself, keeps the socket and reports the port before serving. The new test makes every port this process is handed by the OS one that is already listening; it fails on the old harness and passes here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tests/test_mcp_http_integration.pypicked a port with_free_port()(bind port 0, read the number, close the socket) and passed that number to the server process to bind later. Under xdist another worker can take the port in that window. The(Python 3.13, l-r)shard on #11766 hit exactly that:The race has a quieter failure mode as well: the readiness probe only checks that something accepts connections on the port, so it can connect to whichever process now holds it and hand the tests a URL pointing at the wrong server.
Change
PORT <n>and serves on that socket viauvicorn.Server.run(sockets=[sock]). The harness reads the port from that first line; an early exit ends the pipe and is reported as before._free_portis removed; no port number crosses a process boundary before it is bound.This is a test harness fix only. No product code changes.
Test
test_the_server_comes_up_when_a_port_the_harness_could_pick_is_taken: holds a listening socket and makes every port this process is handed by the OS that one. On the old harness it fails (the returned URL points at the held port); here it passes.tests/test_mcp_http_integration.py: 11 passed, also under-n 4.