Skip to content

WIP: fix(executor): PIPESTATUS wait race — never kill or re-badge a live pipeline member on Unix - #2263

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/2250-pipestatus-race
Oct 30, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/2250-pipestatus-race

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs rubash#2250 — do not merge from this PR description alone; the cluster report carries the full race model and the batched-adjudication plan.

What was wrong

On Unix, two pipeline reap sites shared one defective invariant — "the downstream/last member finished, so a still-living member is a SIGPIPE lingerer: kill it and report 141":

  • the non-Windows concurrent executor's reverse reap: a single try_wait, then a tree-kill plus the synthesized lingerer_sigpipe_status();
  • wait_for_windows_pipeline_member: a 100 ms hard-kill deadline armed on Unix too, from the first observed downstream exit (immediately for the streaming tail's last producer, whose downstream is None).

A downstream exit proves only that the member's write end reached EOF, not that the member died. A member in exit transit (interpreter teardown after its last write, EXIT-trap work, scheduling latency) was SIGKILLed and PIPESTATUS recorded a fabricated 141 — the coin-flip 141 for cmd | cat found by the rubash#2236 battery. GNU never does this: jobs.c:3064 wait_for() blocks with no wall-clock cap and never kills from the wait path; jobs.c process_exit_status() surfaces the reaped status verbatim.

The fix (src/executor/pipeline_exec.rs)

  • Reverse reap: wait for the member's real exit (process.wait()), report it verbatim.
  • Shared member wait: deadline arming and the kill are runtime-gated cfg!(not(unix)) — never armed on Unix; Windows behavior byte-identical (its kill+synthesize contract is rubash#382; Windows has no kernel SIGPIPE).
  • Genuine 141s are preserved: SIGPIPE is SIG_DFL process-wide since rubash#1333, so a member that keeps writing into a dead pipe dies of the kernel's SIGPIPE and is reaped with a real 141 (yes | head -3 guard pin).

Pins + CI home

tests/issue2250_pipestatus_wait_race_regressions.rs (#![cfg(unix)], GNU expectations): two deterministic discriminator pins — a producer that closes fd 1, lingers 1 s and exits 7 must report 7 (concurrent route and streaming-tail route; both report 141 pre-fix) — plus the genuine-SIGPIPE guard and the original shell-child species as a stability pin. The ubuntu rust job gains a named nextest step as their execution home.

Verification status (compile-rationing regime)

Local: cargo check (lib + new test target) green, rustfmt clean, LF verified. Test execution and the three-way sampling adjudication (master / this branch / GNU oracle, via the cluster's probes/sample_pipestatus.py) are batched to the integration side, per the 2026-10-31 regime. The sampling script's close-linger shape is the falsification port: if it does not produce 141s on master, the route analysis in the report needs revisiting before merge.

…mber on Unix

GNU ground truth (bash 5.3.20): jobs.c:3064 wait_for() blocks for each
pipeline member's own exit with no wall-clock cap and never terminates
a member from the wait path; jobs.c process_exit_status() surfaces the
reaped status verbatim. A reported 141 arises only when a member
genuinely died of SIGPIPE.

Two Unix reap sites violated that invariant ("downstream finished =>
the member is a SIGPIPE lingerer: kill it and report 141"):

- the non-Windows concurrent executor's reverse reap used a single
  try_wait, then tree-killed a still-living member and substituted
  lingerer_sigpipe_status();
- wait_for_windows_pipeline_member armed its 100 ms hard-kill
  deadline on Unix too, starting when the downstream exit was first
  observed (immediately, for the streaming tail's last producer).

A downstream exit proves only that the member's write end reached
EOF, not that the member died. A member in exit transit — an
interpreter child's teardown after its last write, EXIT-trap work,
scheduling latency under load — was SIGKILLed and PIPESTATUS recorded
a fabricated 141 (rubash#2250; ~50% for shell-process producers piped
into cat in the rubash#2236 battery, never for /bin/true, never under
a GNU outer).

Fix, mechanism-level: on Unix the reverse reap now waits for the
member's real exit and reports it verbatim, and the shared member
wait's deadline arming and kill are runtime-gated cfg!(not(unix)) so
they can never arm on Unix. Windows — which has no kernel SIGPIPE and
whose kill+synthesize contract is rubash#382 — is byte-identical. A
member that keeps writing into a dead pipe still dies of the kernel's
SIGPIPE on its own (SIGPIPE is SIG_DFL process-wide since
rubash#1333), so genuine 141s arrive as reaped statuses, preserved.

Pins: tests/issue2250_pipestatus_wait_race_regressions.rs — two
deterministic discriminator pins (a producer that closes fd 1,
lingers 1 s and exits 7 must report 7, on both the concurrent route
and the streaming-tail route), a genuine-SIGPIPE guard (yes | head),
and the original shell-child species as a stability pin. Expectations
are GNU behaviour throughout. The ubuntu rust job gains a named
nextest step as the pins' execution home; no CI job ran this target
before.

Local verification under the compile-rationing regime: cargo check
(lib + the new test target) green, rustfmt clean; test execution and
the sampling adjudication (probes in the cluster report) are batched
to the integration side.

Refs rubash#2250
…-race

# Conflicts:
#	.github/workflows/ci.yml
…ot a write race

The streaming-tail pin fed a WRITING producer into a non-reading
tail (`echo hi; exec 1>&-; sleep 1; exit 7 | true`). On that shape
the producer's first write races the consumer's exit: GNU runs the
tail as a forked child (execute_cmd.c:2620 execute_pipeline; the
parent closes its own read-end copy once the children are forked),
so the last read end closes when `true` exits -- almost surely
before an exec'ing interpreter producer lands its first write --
and the producer dies of a genuine kernel SIGPIPE. Measured on
the GNU 5.3.20 oracle, the writing shape reports 141 in 15/15
runs; rubash reports the same value by the same mechanism (no
wait-path synthesis is involved: a never-writing lingerer on this
route is waited out and reports its real 7, and the pre-fix build
kills that shape at the deadline -- master 050d3c8 build: fast
141 x3).

Repair the pin to the close-first producer its own file header
already describes (close fd 1, linger, exit 7): no write exists
that could SIGPIPE, so any 141 can only be the wait path's kill --
pre-fix red, post-fix green, GNU 7. Add a late-write guard pin
locking the consumer-lifetime semantics: a producer writing 0.3 s
after the non-reading tail exited dies of genuine SIGPIPE (141)
in GNU and must keep doing so; holding the read end open until
reap would flip it to 7 and hang `yes | true`.

No product code changes: on the full shape matrix (write-first /
close-first / late-write x cat / true tails) rubash already
matches the GNU oracle cell for cell, and the sampler stays at
100% true values (60 rounds per shape).

Refs #2250
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 18:02
@caomengxuan666
caomengxuan666 merged commit 1049bdd into master Oct 30, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 30, 2026
Resolve external_inner.rs against #2253/#2263: keep the #2235 stash lookup ahead of the #2270 heredoc arm (a heredoc entry still classifies as write at lookup time, so it can never claim a stash — matching the dup replay, which kind-skips heredocs; a same-fd stash belongs to an earlier plain entry and the heredoc's later stamp preserves last-wins). Semantic check: diff vs master is exactly this PR's change set.

Refs #2270
@caomengxuan666
caomengxuan666 deleted the fix/2250-pipestatus-race branch November 2, 2026 01:08
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