Repository navigation
libobs/util: Stop counting discarded data in os_process_pipe_write - #265
Merged
Merged
Conversation
On Linux, a dd child reads one byte of a 16 MiB write and exits. The write must report a positive short count (the prefix the kernel took before EPIPE), and the next write must report 0. os_process_pipe_write retries fwrite until it returns 0, and after an error glibc's fwrite copies 4096 bytes into its buffer, fails the flush, discards them and still returns 4096. So the function reports the full 16 MiB as written, and the test fails until the next commit (20 of 20 runs: "written < len is not true"). Refs 264 Co-Authored-By: Claude Opus 5.5 <[email protected]>
A short fwrite already reports an error. The loop retried it until fwrite returned 0; after the first failure, each retry copied up to 4096 bytes into the stdio buffer, failed to flush and discarded them, yet returned the copied count. A write to a child that had exited so reported the full length, and obs-ffmpeg-mux, which only checks ret != size, kept sending packets to a dead ffmpeg-mux with no error. os_process_pipe_write now returns the result of one fwrite: the full length on success, the accepted prefix on a write error, and 0 once the stream has an error. Fixes 264 Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
pushed a commit
that referenced
this pull request
Oct 11, 2026
#265 merged with one line of test_pipe_write_stops_after_partial_error not clang-formatted, so the clang-format check (and the local-gate lint lane in Rust Tests) fails on master. Formatting only. 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 #264. Root cause from the #192 investigation; details and the syscall trace are on #192.
Bug
os_process_pipe_write(pipe-posix.c) retriedfwriteuntil it returned 0. A shortfwritealready reports an error, and after one, glibc'sfwritecopies up to 4096 bytes into the stdio buffer, fails the flush withEPIPE, discards them and still returns the copied count. So a write to a child that has exited reported the full length: the kernel took at most one pipe buffer (64 KiB) beforeEPIPE, and nothing ever read it.Impact: the frontend blocks SIGPIPE, and
obs-ffmpeg-mux.cwrites every recorded packet toffmpeg-muxwith this function, failing only onret != size. Ifffmpeg-muxdies mid-recording, every later write "succeeds", so OBS keeps recording and discards everything, with no failure signalled until stop.Commits
test/cmocka/test_pipe.c, Linux): add bs=1 count=1 of=/dev/nullchild (stderr closed first, so draining it can't block) reads one byte of a 16 MiB write and exits.0 < written < len, and the next write must report 0.ddcan't exit before the first byte arrives, so the short count is deterministic.fwrite: the full length on success, the accepted prefix on a write error, and 0 onceferroris set. The Rust core's doc comment onPipe::writedrops the mention of the old loop. Its behavior already matched: it writes unbuffered and returns real byte counts.One behavior to note: after any write error the stream stays in its error state, so later writes return 0. That's what callers want for
EPIPE. A write interrupted by a signal could also set it, but pipe writes with SIGPIPE blocked rarely seeEINTR, and the old loop didn't recover meaningfully either.Testing
On Ubuntu 26.04 (WSL2), gcc 15, real cmocka 2.0, with
test_pipe.cbuilt againstpipe.c,dstr.c,dstr-libc.cand the two versions ofpipe-posix.c:written < len is not true); the 14 other tests pass.cargo test -p obs-util --test pipe --test pipe_paritypasses 3/3 with the fixed C as the oracle.Windows (
pipe-windows.c) does oneWriteFileper call and isn't affected.The root cause, the standalone reproduction and the trace come from a separate investigation that I ran; I re-verified the fix and the test on current master as above.
🤖 Generated with Claude Code