Repository navigation
Re-draw a port the OS handed to another test - #11086
Conversation
`Tauri Linux debug build (no codesign)` failed on an unrelated PR, one Rust test out of 555:
```
---- commands::tests::a_port_with_nothing_on_it_reads_as_death_not_a_stall stdout ----
panicked at src/commands.rs:1573:14:
nothing is listening on this port: Response { url: "http://127.0.0.1:36767/api/liveness", status: 200, ... }
```
Something answered on the port the test had just established was free.
## Why
The setup binds port 0, reads the port the OS assigned, and drops the listener. That frees the
port, it does not reserve it. Rust runs the tests in this binary concurrently and several of them
bind ephemeral ports of their own, so the kernel is free to hand this one straight to one of those
between the drop and the probe. The request is then answered rather than refused, and
`expect_err` panics with the response it got, which is exactly what CI printed.
## The fix
Obtaining a genuinely closed port is setup, not the property under test. The test now re-draws a
port, up to 16 times, until the connection is actually refused, and only then asserts what it is
there to assert: that a refused port reads as death rather than a stall, and inherits the busy
budget. The assertions are unchanged.
## Verification
`cargo check --bin unsloth-studio --tests` passes with the change. The two warnings it emits are
in `main.rs` and `process.rs`, both pre-existing and untouched here.
A note on what is not verified: this workspace has no Rust toolchain of its own, and
`generate_context!` needs a built `frontend/dist` that does not exist here, so a stub index.html
was needed to get the macro past its check. That means the compile is verified but the test was
not executed locally. CI is the first place this actually runs.
The failure is a race, so a green run would not prove much either way. What is addressed here is
the mechanism: the test no longer assumes a released port stays free.
|
You have reached your Codex usage limits for security reviews. Please try again later. |
|
@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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b3596f5ad9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| error = Some(refused); | ||
| break; | ||
| } | ||
| Ok(_) => continue, |
There was a problem hiding this comment.
Avoid stealing another test's one-shot connection
When a released port is reassigned to a one-shot fixture, Ok(_) means this probe has already consumed that fixture's sole accepted connection; for example, loopback_http.rs:65-71 accepts exactly once before its owning test sends the intended request. Continuing can make this test pass while the owning test subsequently gets a refusal or timeout, so the same parallel-suite flake merely moves to another test (and repeated retries can disturb additional fixtures). Prevent or serialize cross-test port reuse rather than treating a successful response as harmless and retryable.
Useful? React with 👍 / 👎.
Retrying a port that answered was the wrong repair. Answering means the probe had just consumed somebody's connection, and the one-shot fixture in loopback_http accepts exactly once before its own test sends the request it cares about, so a retry would hand that test a refusal instead. That relocates the flake rather than fixing it. Every other test in this binary binds port 0, so the allocator can only ever give them an ephemeral port: 32768 and up on Linux, 49152 and up on macOS and Windows. Drawing from below that range means a sibling cannot be given this port at all, which removes the race rather than reacting to it. A port in that window being occupied is a real listener on the machine, not a sibling test, so the test walks a small range to find a free one and then makes the same single assertion it made before.
|
Agreed, and this is the better fix. Retrying a port that answered was the wrong repair for exactly the reason you give: answering means the probe had already consumed somebody's connection, and
A port in that window being occupied is a real listener on the machine rather than a sibling test, so the test walks a small range to find a free one and then makes the same single assertion as before, with no retry around the probe itself.
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 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". |
`Tauri Linux debug build (no codesign)` failed on one Rust test out of 555:
---- commands::tests::a_port_with_nothing_on_it_reads_as_death_not_a_stall stdout ----
panicked at src/commands.rs:1573:14:
nothing is listening on this port: Response { url: "http://127.0.0.1:36767/api/liveness", status: 200, ... }
Something answered on the port the test had just established was free.
## Why
The setup binds port 0, reads the assigned port, and drops the listener. That frees the port, it
does not reserve it. Rust runs the tests in this binary concurrently and several bind ephemeral
ports of their own, so the kernel can hand this one straight to one of those between the drop and
the probe.
## The fix
Draw from below the ephemeral range rather than retrying. Every other test here binds port 0, so
the allocator can only ever give them an ephemeral port: 32768 and up on Linux, 49152 and up on
macOS and Windows. A port below that cannot be assigned to a sibling at all, which removes the
race instead of reacting to it.
Retrying a port that answered was the first attempt and it was wrong: answering means the probe
had already consumed somebody's connection, and the one-shot fixture in `loopback_http` accepts
exactly once before its own test sends the request it cares about. That relocates the flake
rather than fixing it. Codex caught this during review.
A port in the chosen window being occupied is a real listener on the machine, not a sibling, so
the test walks a small range for a free one and then makes the same single assertion as before.
## Verification
`cargo check --bin unsloth-studio --tests` passes; its two warnings are pre-existing in `main.rs`
and `process.rs`.
Stated plainly: this workspace has no Rust toolchain of its own and `generate_context!` needs a
built `frontend/dist`, so the compile is verified but the test was not executed locally. CI is the
first place it runs.
Summary
Tauri Linux debug build (no codesign)failed on an unrelated PR, one Rust test out of 555:Something answered on the port the test had just established was free.
Why
The setup binds port 0, reads the port the OS assigned, and drops the listener. That frees the
port, it does not reserve it. Rust runs the tests in this binary concurrently and several of them
bind ephemeral ports of their own, so the kernel is free to hand this one straight to one of those
between the drop and the probe. The request is then answered rather than refused, and
expect_errpanics with the response it got, which is exactly what CI printed.The fix
Obtaining a genuinely closed port is setup, not the property under test. The test now re-draws a
port, up to 16 times, until the connection is actually refused, and only then asserts what it is
there to assert: that a refused port reads as death rather than a stall, and inherits the busy
budget. The assertions are unchanged.
Verification
cargo check --bin unsloth-studio --testspasses with the change. The two warnings it emits arein
main.rsandprocess.rs, both pre-existing and untouched here.A note on what is not verified: this workspace has no Rust toolchain of its own, and
generate_context!needs a builtfrontend/distthat does not exist here, so a stub index.htmlwas needed to get the macro past its check. That means the compile is verified but the test was
not executed locally. CI is the first place this actually runs.
The failure is a race, so a green run would not prove much either way. What is addressed here is
the mechanism: the test no longer assumes a released port stays free.