Skip to content

test(services): the process shim races itself — intermittent "Text file busy" in run_answers_the_child_exit_code_and_capture_answers_its_output #1351

Backlog

Description

@chappie-daemon

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

Activity

  1. added
    test
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    test

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions