Repository navigation
Conversation
…er busy when run
`freshness::tests::installed_version_uses_env_snapshot` failed once in
Crates CI (run 46581441992, on a PR that changes nothing under
crates/doctor) with `left: None, right: Some("1.2.3")`, the crate's other
159 tests passing. The request was to find the cause, fix it without a
retry or a longer wait, and fix the sibling tests that share it.
The cause is in the tests, not in Doctor. Each of them writes a shell
script with `std::fs::write`, marks it executable and has Doctor run it at
once. Linux refuses to execute a file that any process has open for
writing (ETXTBSY, "Text file busy"). The tests run on parallel threads and
most of them spawn processes: a child forked by another test while the
script is open for writing inherits that descriptor and keeps it until its
own exec. A script run in that window does not start. Doctor reports a
probe that could not start as a missing version or a failed check, which
is the right answer for a tool that cannot be run, so the test fails on an
assertion that names no cause. macOS has no such check, so it never shows
locally. It is not the probe's 15 s limit: the CI log prints the failure
within milliseconds of the test binary starting.
The fix removes the descriptor instead of waiting it out. A new
`test_support::write_executable` has a child `sh` write the file and sets
the mode by path, so the test binary never opens a script for writing and
there is nothing for a concurrent fork to inherit. The writer has exited
before the helper returns. It replaces the four copies of
`write_executable` (freshness, agents, resolve, lib) and the three tests
that wrote a script inline (checks, resolve, lib). No product code
changes.
Two tests are added beside the helper: the contents are written byte for
byte, and a script runs at once while two other threads spawn processes
without a pause, which is the race forced.
Measured on Linux (Ubuntu 24.04 container, 16 CPUs, the test binary built
from this tree before and after):
- The CI test alone, 2000 runs: 0 failed before, 0 after. It needs the
other tests' forks.
- The whole suite, 8 loops side by side, 320 runs: 13 failed before, 0
after. With 16 busy loops added for CPU contention, 320 runs: 2 failed
before, 0 after.
- The 15 failed runs were five tests, all of which run a script they
wrote: `checks::check_git_receives_env_snapshot` (10),
`freshness::installed_version_uses_env_snapshot` (2, the CI failure),
two `exec_command_with_*_env_snapshot*` tests in lib and
`agents::unknown_auth_status_carries_login_command_without_a_fix` (1
each). With the spawn error printed, all 12 failures of the first two,
which spawn the script directly, were
`Os { code: 26, kind: ExecutableFileBusy }`. The other three run it
through a shell, where a busy script is an exit status; the agents
failure read the shell's 126 as signed out. The text of the two lib
failures was not kept.
- Forced, 2000 write-then-run rounds with the old helper: 0 busy with no
other thread spawning, 25 with one, 102 with four.
- The new forced test with the old in-process write put back into the
helper: 295 of 300 runs fail. With the fix: 0 of 300.
`cargo fmt --check`, `cargo clippy --workspace -- -D warnings` and
`cargo test -p doctor` (162 passed) pass on macOS.
Signed-off-by: Matt Toohey <contact@matttoohey.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis 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. |
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.
Symptom
freshness::tests::installed_version_uses_env_snapshotin thedoctorcrate failed once in Crates CI, run 46581441992 (PR #1112, which changes nothing undercrates/doctor), with the crate's other 159 tests passing:Crates CI passed on the same crate sources before and after that run.
Cause
The tests are wrong; Doctor is not.
std::fs::write, marks it executable and has Doctor run it at once.ETXTBSY, "Text file busy").It is not the probe's 15 s limit: the CI log prints the failure within milliseconds of the test binary starting, and the whole suite finished in 6.1 s.
Fix
The fix removes the descriptor instead of waiting it out. There is no retry and no sleep.
crates/doctor/src/test_support.rswith onewrite_executable: a childshwrites the file and the mode is set by path. The test binary never opens a script for writing, so there is nothing for a concurrent fork to inherit. The writer has exited before the helper returns.write_executable(freshness,agents,resolve,lib) and the three tests that wrote a script inline (checks,resolve,lib).Before and after
Linux, Ubuntu 24.04 container with 16 CPUs, the test binary built from this tree before and after the change.
checks::check_git_receives_env_snapshot(10),freshness::installed_version_uses_env_snapshot(2, the CI failure), twoexec_command_with_*_env_snapshot*tests inlibandagents::unknown_auth_status_carries_login_command_without_a_fix(1 each).Os { code: 26, kind: ExecutableFileBusy, message: "Text file busy" }. The other three run it through a shell, where a busy script is an exit status. The text of the twolibfailures was not kept.cargo fmt --check,cargo clippy --workspace -- -D warningsandcargo test -p doctor(162 passed) pass on macOS.cargo test --workspacewas not run locally.Not in this change
Tests in
crates/acp-clientandcrates/blox-cliwrite scripts the same way. They were not seen to fail and are left alone here.🤖 Generated with Claude Code