Skip to content

Commit 59b5f3b

Browse files
hyperpolymathclaude
andcommitted
process_sub: add UUID v4 to FIFO path; fixes test_fifo_path_unique race
The pre-existing FIFO-path generator /tmp/vsh-fifo-<pid>-<counter> collided when two ShellState instances shared a pid (e.g., parallel cargo tests where each test creates a fresh state with the AtomicUsize counter starting at 0). The first mkfifo wins; the second hits AlreadyExists and races the first test's cleanup. Surfaced as an intermittent failure of `process_sub::tests::test_fifo_path_unique` during this session's batch-7 verification run; passed in isolation. Fix: append a UUID v4 suffix: /tmp/vsh-fifo-<pid>-<counter>-<uuidv4> uuid v1.22 with the v4 feature is already a dep of this crate (originally for operation IDs in audit logs). The pid + counter remain useful for grep/debugging discrimination; the UUID makes collisions cryptographically improbable across: * two parallel tests in the same binary * two `vsh` processes that happen to share a recycled pid * two FIFOs in the same process (counter handles this anyway) Verified locally: cargo build -> EXIT 0 Stress loop: 10/10 runs of the process_sub::tests:: suite all pass (was failing intermittently when called via full `cargo test` due to parallel scheduling). Full suite: 703 passed / 0 failed / 14 ignored — unchanged. This is a real production fix, not just a test fix: the same `/tmp/vsh-fifo-<pid>-<counter>` collision could affect production when multiple containerised vsh instances share a pid namespace. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8fad444 commit 59b5f3b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

impl/rust-cli/src/process_sub.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,16 @@ impl ProcessSubstitution {
4040
cmd: String,
4141
state: &mut ShellState,
4242
) -> Result<Self> {
43-
// Generate unique FIFO path: /tmp/vsh-fifo-<pid>-<counter>
43+
// Generate globally-unique FIFO path:
44+
// /tmp/vsh-fifo-<pid>-<counter>-<uuidv4>
45+
// The pid + counter make collisions improbable in single-process use;
46+
// the UUID v4 suffix prevents collisions when two ShellState
47+
// instances share a pid (e.g., parallel cargo tests where each test
48+
// creates a fresh state with counter starting at 0).
4449
let pid = std::process::id();
4550
let fifo_id = state.next_fifo_id();
46-
let fifo_path = PathBuf::from(format!("/tmp/vsh-fifo-{}-{}", pid, fifo_id));
51+
let unique = uuid::Uuid::new_v4().simple();
52+
let fifo_path = PathBuf::from(format!("/tmp/vsh-fifo-{}-{}-{}", pid, fifo_id, unique));
4753

4854
// Create FIFO using mkfifo(2) syscall
4955
#[cfg(unix)]

0 commit comments

Comments
 (0)