Repository navigation
fix(executor): report SIGPIPE death for pipeline producers whose reader closed early (Refs #2693) - #3697
Merged
Conversation
…er closed early (Refs #2693) GNU forks every pipeline element (execute_cmd.c:2620 execute_pipeline) and the child restores untrapped dispositions (trap.c:1480 reset_signal_handlers via execute_cmd.c:1670), so an element writing a pipe whose reader exited dies by SIGPIPE and PIPESTATUS reports 141. The sequential stage loop's forkless emulation captures each producer's output and feeds the next member's stdin from a writer thread; the feed swallowed EPIPE and in-process members never touched a pipe at all, so `printf 'y\n%.0s' $(seq 200000) | head -1` reported ps0=0. Two verdicts now reconstruct GNU's outcome at the consumer boundary: * A spawned member's writer thread reports whether its payload write ended in EPIPE (`pipeline_stage_feed_sigpipe`); the driver rewrites the preceding member's status to 141. * An in-process member (inline arm / builtin stage) reports its measured reads via the existing `pipeline_stdin_consumed` channel; the producer had writes still pending when the reader went away iff written > read + PIPE_STAGE_CAPACITY (the 64 KiB pipe(2) default). GNU 5.3.20 oracle probes (script files, WSL): 400KB->head -1 gives 141, 60KB gives 0, 100KB->true gives 141, seq|cat|head gives 141 141 0 — all matched byte-for-byte. The sub-capacity multi-write zone (GNU dies below 64KB when the producer emits many small writes) remains a documented divergence; the pin's contract is the capacity model. Pin: tests/issue2693_pipeline_builtin_sigpipe.rs 4/4 green. Adjacent: issue1580/1363/1364/1525/1566/1540/1552/1571/1462/158 pipeline & PIPESTATUS pins all green.
This was referenced Nov 15, 2026
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.
Summary
printf 'y\n%.0s' $(seq 200000) | head -1reportedPIPESTATUS[0]=0; GNU bash 5.3.20 reports 141. A builtin pipeline producer whose consumer closes early is SIGPIPE-immune under the forkless stage emulation.reset_signal_handlersleaves SIGPIPE atSIG_DFL(trap.c:1480 via execute_cmd.c:1670), so the producer dies on the broken write. Rubash's sequential stage loop captures the producer's output and feeds the consumer's stdin from a writer thread; the feed swallowed EPIPE, and in-process members (inlinehead/cat/builtin stages) never touched a pipe at all.pipeline_stage_feed_sigpipe); the driver rewrites the preceding member's status to 141.pipeline_stdin_consumedchannel; the producer had writes pending at reader-close iffwritten > read + PIPE_STAGE_CAPACITY(64 KiB pipe(2) default). A producer already dead by another signal (status >= 128) is left alone.Oracle evidence (WSL GNU bash 5.3.20, script files)
printf 400KB | head -1printf 60KB | head -1printf 100KB | trueseq 200000 | cat | head -1printf 200KB | wc -c(reads all)Whole probe file byte-identical. Known residual divergence: GNU also kills sub-capacity producers that emit many small writes (e.g. 65400 bytes via ~32k writes → 141); that is a write-granularity scheduling artifact the byte-capacity model cannot see — pin contract documents the capacity model.
Legs
tests/issue2693_pipeline_builtin_sigpipe.rs: 4/4 green (was 3/4 —printf_stage_dies_by_sigpipered on master).cargo fmt --checkclean;RUSTFLAGS="-D warnings" cargo build --lockedclean (cargo-clippy unavailable on stable toolchain).fail-first:
printf_stage_dies_by_sigpipered on master (ps0=0 ps1=0), matches the pin's RED cell.