Skip to content

fix(executor): report SIGPIPE death for pipeline producers whose reader closed early (Refs #2693) - #3697

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2693-builtin-stage-sigpipe
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2693-builtin-stage-sigpipe

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

  • Problem: printf 'y\n%.0s' $(seq 200000) | head -1 reported PIPESTATUS[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.
  • Root cause: GNU's element is a real child writing the inter-member pipe itself — reset_signal_handlers leaves SIGPIPE at SIG_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 (inline head/cat/builtin stages) never touched a pipe at all.
  • Fix: two verdicts reconstruct GNU's outcome at the consumer boundary in the sequential stage loop:
    1. The writer thread reports whether its payload write ended in EPIPE (pipeline_stage_feed_sigpipe); the driver rewrites the preceding member's status to 141.
    2. In-process members report measured reads via the existing pipeline_stdin_consumed channel; the producer had writes pending at reader-close iff written > 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)

Case GNU rubash (after)
printf 400KB | head -1 141 0 141 0
printf 60KB | head -1 0 0 0 0
printf 100KB | true 141 0 141 0
seq 200000 | cat | head -1 141 141 0 141 141 0
printf 200KB | wc -c (reads all) 0 0 0 0

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

  • Pin tests/issue2693_pipeline_builtin_sigpipe.rs: 4/4 green (was 3/4 — printf_stage_dies_by_sigpipe red on master).
  • Adjacent pins green: issue1580 (4), issue1363 (21), issue1364 (12), issue1525 (8), issue1566 (12), issue1540, issue1552, issue1571, issue1462 (9), issue158 (8).
  • cargo fmt --check clean; RUSTFLAGS="-D warnings" cargo build --locked clean (cargo-clippy unavailable on stable toolchain).

fail-first: printf_stage_dies_by_sigpipe red on master (ps0=0 ps1=0), matches the pin's RED cell.

…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.
@caomengxuan666
caomengxuan666 merged commit 2cf1e28 into master Nov 15, 2026
7 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant