Repository navigation
test: Serialize spawning in pipe_parity (#192) - #260
Merged
Merged
Conversation
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]>
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.
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
repro/192-pipe-parity-race, authorship kept):dead_pipe_write_survives_concurrent_spawns. It fails 2 of 3000 on my Ubuntu 26.04 VM.pipe_parity.rsthat spawns holds onestatic SPAWN: Mutex<()>(serial()).dead_pipe_write_matches_oracle's doc comment, which the RED commit separated from it, goes back onto it.Why spawns leak into each other (details in #192)
pipe-posix.ccreates its pipes withpipe()and only then setsFD_CLOEXEC. A spawn on another thread in that window inherits them for the child's whole life. A/procscan during a leaked write found a spawner'ssh -cand itssleep 0.05holding both ends of the dead child's stdin pipe, withoutO_CLOEXEC.pipe2(O_CLOEXEC)I still saw 1 leak in 9000.The oracle stays byte-for-byte the original C.
Testing
cargo test -p obs-util --test pipe_paritypasses 5 times in a row, which is 15,000 dead-pipe writes with 16 spawning threads and none leaked.pipeandexport_listalso pass.cargo clippy -p obs-util --tests -- -D warningsis clean.cargo fmt --checkis clean. The local lint lane fails only inci/test_versionconfig.py, which fails on its own here:FileNotFoundError, then aPermissionErrordeleting its temp.git. That's a Windows-only problem with the new release-version tests, unrelated to this PR.🤖 Generated with Claude Code