You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(services): the process shim races itself — intermittent "Text file busy" in run_answers_the_child_exit_code_and_capture_answers_its_output #1351
cargo test -p nostream-services --lib fails intermittently with
the child runs: Spawn { program: "/tmp/.tmpQpdddb/env-check", message: "Text file busy (os error 26)" }
at crates/nostream-services/src/process.rs:362
It hit the Rust Checks job on #1350, whose diff touches no nostream-services file.
Measured
With --test-threads=8, on two trees that have identical nostream-services sources:
Tree
Failures
e5a78d70 (rewrite/main)
4 of 15 runs
a branch off it touching only nostream-config, nostream-admin, nostream-mcp
3 of 15 runs
Every failure is the same case, run_answers_the_child_exit_code_and_capture_answers_its_output, and every one is ETXTBSY on that test's own env-check shim. At the default test-thread count it passed 15 of 15 in the same loop, so it is a race, not a broken fixture.
Why
shim() (process.rs:279) writes the script with std::fs::write and then makes it executable. The fd it writes through is O_CLOEXEC, but the tests run in parallel threads: when another thread's Command::spawn forks inside that write window, the child holds the new script open for writing until it execs, and the exec of env-check answers ETXTBSY. Scripts written by fs::write and executed by a nearby spawn cannot be made safe by closing earlier — the window belongs to the forking thread, not the writing one.
Suggested fix
Write the shim under a temporary name and std::fs::rename it into place: the rename swaps the inode, so the exec'd path is never the one a writer holds open. A retry loop on ETXTBSY would also work but leaves the race in place.
Simplest reproduction:
for i in $(seq 1 15); do cargo test -q -p nostream-services --lib -- --test-threads=8; done
Hi @cameri@chappie-daemon, I'd like to take this one. My plan is to reproduce the flake first (the 15-run loop at --test-threads=8), then write the shim to a temp name and rename it into place as suggested, and re-measure over a larger number of runs. Since ETXTBSY follows the inode rather than the path, I'll also check whether a forked child can still hold the write descriptor after the rename, and if so I'd add a lock around write-and-spawn or retry on ETXTBSY. Could you assign it to me?
I have a fix ready on my fork (ItsAbir005/nostream, branch fix/1351-process-shim-race, fork PR ItsAbir005#3) if I can be assigned to open the PR against rewrite/main.
Thank you @ItsAbir005 — #1358 carries your commit (1f641f23, cherry-picked with -x as 497930d5, authorship preserved) into rewrite/main. The fork-PR route into this repo needs a permission this account does not hold, so the branch lives here instead; your own PR ItsAbir005#3 links to it.
Verified locally before opening: cargo test -p nostream-services --lib process::tests (5 passed) and the reproduction loop from this issue, 15 consecutive runs at --test-threads=8, 0 failures.
Fixed by #1358, merged as e7ce03e7 on rewrite/main. The shim is now written to a unique temporary file in the same directory, closed, chmodded and renamed into place, so the test's own spawn cannot inherit a write descriptor on the file it is about to execute.
Authored by @ItsAbir005; thanks also to @avantikonde, whose #1357 named the mechanism and is kept as the fallback if the narrow fork window ever recurs.
Verification on the merged commit: cargo test -p nostream-services --lib process::tests (5 passed) and 15 consecutive runs at --test-threads=8 with 0 failures; CI green on the required contexts.
Activity
ItsAbir005 commentedon Dec 3, 2026
Hi @cameri @chappie-daemon, I'd like to take this one. My plan is to reproduce the flake first (the 15-run loop at --test-threads=8), then write the shim to a temp name and rename it into place as suggested, and re-measure over a larger number of runs. Since ETXTBSY follows the inode rather than the path, I'll also check whether a forked child can still hold the write descriptor after the rename, and if so I'd add a lock around write-and-spawn or retry on ETXTBSY. Could you assign it to me?
ItsAbir005 commentedon Dec 3, 2026
I have a fix ready on my fork (ItsAbir005/nostream, branch fix/1351-process-shim-race, fork PR ItsAbir005#3) if I can be assigned to open the PR against rewrite/main.
cameri commentedon Dec 3, 2026
Assigned to @ItsAbir005
ItsAbir005 commentedon Dec 3, 2026
@cameri @chappie-daemon I have also raised the PR at ItsAbir005#3 pls review
chappie-daemon commentedon Dec 3, 2026
Thank you @ItsAbir005 — #1358 carries your commit (
1f641f23, cherry-picked with-xas497930d5, authorship preserved) intorewrite/main. The fork-PR route into this repo needs a permission this account does not hold, so the branch lives here instead; your own PR ItsAbir005#3 links to it.Verified locally before opening:
cargo test -p nostream-services --lib process::tests(5 passed) and the reproduction loop from this issue, 15 consecutive runs at--test-threads=8, 0 failures.test(services): invoke /bin/sh directly in process tests
test(services): write the process shim atomically (#1351) (#1358)
chappie-daemon commentedon Dec 3, 2026
Fixed by #1358, merged as
e7ce03e7onrewrite/main. The shim is now written to a unique temporary file in the same directory, closed, chmodded and renamed into place, so the test's own spawn cannot inherit a write descriptor on the file it is about to execute.Authored by @ItsAbir005; thanks also to @avantikonde, whose #1357 named the mechanism and is kept as the fallback if the narrow fork window ever recurs.
Verification on the merged commit:
cargo test -p nostream-services --lib process::tests(5 passed) and 15 consecutive runs at--test-threads=8with 0 failures; CI green on the required contexts.test(services): write the process shim atomically
test(services): invoke /bin/sh directly in process tests (#1351) (#1360)
test(services): invoke /bin/sh directly in process tests