Skip to content

test: Serialize spawning in pipe_parity (#192) - #260

Merged
zackees merged 2 commits into
obs-rust:masterfrom
b7216309-jpg:fix/192-serialize-spawns
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
b7216309-jpg:fix/192-serialize-spawns

Conversation

@b7216309-jpg

Copy link
Copy Markdown
Contributor

Fixes #192. This is the test half of the plan there; the pipe2(O_CLOEXEC) C fix will be its own issue and PR.

Commits

  1. RED (@zackees, cherry-picked from repro/192-pipe-parity-race, authorship kept): dead_pipe_write_survives_concurrent_spawns. It fails 2 of 3000 on my Ubuntu 26.04 VM.
  2. GREEN: every test in pipe_parity.rs that spawns holds one static SPAWN: Mutex<()> (serial()).
    • The stress test keeps its 16 spawner threads. Each spawn takes the lock, and each dead-pipe iteration holds it from create to destroy, so no spawn can land in between.
    • dead_pipe_write_matches_oracle's doc comment, which the RED commit separated from it, goes back onto it.
    • One long line from the RED commit is wrapped by rustfmt.

Why spawns leak into each other (details in #192)

  • pipe-posix.c creates its pipes with pipe() and only then sets FD_CLOEXEC. A spawn on another thread in that window inherits them for the child's whole life. A /proc scan during a leaked write found a spawner's sh -c and its sleep 0.05 holding both ends of the dead child's stdin pipe, without O_CLOEXEC.
  • Separately, any child holds copies of every fd until it execs. With pipe2(O_CLOEXEC) I still saw 1 leak in 9000.

The oracle stays byte-for-byte the original C.

Testing

  • On Ubuntu 26.04 (WSL2, kernel 6.18):
    • cargo test -p obs-util --test pipe_parity passes 5 times in a row, which is 15,000 dead-pipe writes with 16 spawning threads and none leaked.
    • pipe and export_list also pass.
    • cargo clippy -p obs-util --tests -- -D warnings is clean.
    • Without the lock, the same run leaks 2–6 writes per 3000.
  • On Windows: cargo fmt --check is clean. The local lint lane fails only in ci/test_versionconfig.py, which fails on its own here: FileNotFoundError, then a PermissionError deleting its temp .git. That's a Windows-only problem with the new release-version tests, unrelated to this PR.

🤖 Generated with Claude Code

zackees and others added 2 commits October 11, 2026 22:20
libobs/util/pipe-posix.c creates its pipes with pipe() and sets
FD_CLOEXEC with fcntl() afterwards. A process spawned on another thread
in that window inherits the fds, keeps a dead child's stdin open, and a
write that should fail goes through. That made
dead_pipe_write_matches_oracle flaky (obs-rust#192).
dead_pipe_write_survives_concurrent_spawns runs 16 spawner threads
against 3000 dead-pipe writes: 11 and 9 leaked writes in two runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every test in pipe_parity.rs that spawns now holds one lock, `serial`.
A spawn on another thread can keep a test's pipe open, so a write to a
dead child went through (obs-rust#192):

- pipe-posix.c creates its pipes with pipe() and only then sets
  FD_CLOEXEC, so a child spawned in between inherits them for its whole
  life. On Linux, a scan of /proc during a leaked write found a spawner's
  `sh -c` and its `sleep 0.05` holding both ends of the dead child's
  stdin pipe without O_CLOEXEC.
- any child holds copies of every fd until it execs.

The oracle stays the original C; the C fix (pipe2 with O_CLOEXEC) is
separate. dead_pipe_write_survives_concurrent_spawns keeps its 16
spawner threads, which now take the lock for each spawn; the dead-pipe
scenario holds it from create to destroy. On Ubuntu 26.04 (WSL2), 5 runs
of pipe_parity pass, against 2 to 6 leaked writes in 3000 without it.

Also puts dead_pipe_write_matches_oracle's doc comment back on it.

Fixes obs-rust#192

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@b7216309-jpg
b7216309-jpg requested a review from zackees as a code owner October 11, 2026 20:23
@zackees
zackees merged commit ed8cbb6 into obs-rust:master Oct 11, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Flaky: pipe_parity dead_pipe_write_matches_oracle (oracle write returns full length)

2 participants