Skip to content

WIP: fix(executor): complete output-procsub feeds before the process lifetime ends (#2179) - #2182

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2179-procsub-exit-feed
Oct 30, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2179-procsub-exit-feed

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2179

Defect

An output process substitution's payload is intermittently lost when the shell exits right after the producing command: the consumer reads EOF and prints nothing. The two victim pins in cli_tests::compat_issue_regressions (output_process_substitution_preserves_printf_raw_bytes, shell_read_with_input_and_output_process_substitutions_preserves_streams) flake with empty stdout.

Localization (evidence in the cluster REPORT)

The consumer body runs as a respawned rubash -c child whose stdin is fed from the temp carrier by a detached writer thread (spawn_output_process_substitution_child). Instrumented runs show that in failing runs the thread had never been scheduled before main() joined the shell thread and called std::process::exit — one strace capture shows it destroyed mid-feed. The payload never entered the pipe; the consumer then saw EOF when the dying process closed the write end.

GNU has no such leg: process_substitute (subst.c:6362) forks the consumer at materialization and the producer's own writes fill the live pipe during the command, so at shell exit the transfer is already complete. Measured under identical read-to-EOF capture (60 runs each): GNU bash 5.3.20 loses 0/60 on both victim shapes; rubash lost 16–28/60 and 8–10/60.

Fix

The feed is no longer fire-and-forget:

  • Feed JoinHandles live on the Executor (procsub_feed_handles, finished handles pruned at the next spawn).
  • New drain_procsub_feeds joins them at every end of the executor's process lifetime:
    • Executor::drop — placed ahead of the process-exit early return, because a feed's payload is observable outside the dying process (unlike the environment restore that skip exists for);
    • the exec builtin's image replacement (both dispatcher sites);
    • the nofork tail replacement (external_inner).

Joining completes only the shell's own transfer (payload in the pipe, or the consumer already gone). The consumer is not waited for — it keeps running detached exactly like GNU's async child, so the #1220 async contract is unchanged (verified: a consumer that sleeps 5s before reading — the shell process exits in ~0.02s and the payload is still delivered). A payload larger than the pipe buffer is now delivered in full: pre-fix, seq 100000 > >(wc -c) counted exactly 65536 (the abandoned thread had filled one pipe buffer); post-fix it counts 588895, matching GNU.

Pins

  • New: tests/issue2179_procsub_exit_feed_regressions.rs — both victim shapes ×30 repetitions (pre-fix per-rep pass rates make 30 consecutive passes unreachable by timing luck), exec-replacement and tail-replacement guards, full delivery of a 588895-byte payload. All 5 pass.
  • The two victim pins are untouched: the product fix makes them pass as written — 200 consecutive runs each in the acceptance pass (see cluster REPORT), plus the full procsub neighborhood (cli_tests process_substitution module, issue1220/1221 async/write-once pins, issue1659/2053/2057 families).

Adjacency

No changes to src/executor/dev_fd_operands.rs or tests/regression.rs (PR #2156's surface) — localization proved the defect lives in the feed-thread lifetime, not the operand materialization. No fifo-marker protocol bytes touched.

Local verification is targeted (new pin target + cli_tests subsets + lib subsets); full verification via this PR's CI — the Windows goldens job and the Rust tests jobs are the adjudicators.

…ime ends (rubash#2179)

Refs #2179

An output process substitution's payload was intermittently lost when
the shell exited right after the producing command: the consumer read
EOF and printed nothing (the two victim pins in
cli_tests::compat_issue_regressions flaked with empty stdout).

Localization (instrumented build + strace, see cluster REPORT): the
consumer body runs as a respawned child whose stdin is fed from the
temp carrier by a detached writer thread
(spawn_output_process_substitution_child). In failing runs that
thread had never been scheduled — in one capture it was destroyed by
exit_group mid-write — before main() joined the shell thread and
called std::process::exit. The payload never entered the pipe.

GNU has no such leg: process_substitute (subst.c:6362) forks the
consumer at materialization and the producer's own writes fill the
live pipe during the command, so at shell exit the transfer is
already complete (measured: GNU bash 5.3.20 loses 0/60 on both victim
shapes under read-to-EOF capture; rubash lost 16-28/60 and 8-10/60).

Fix: the feed is no longer fire-and-forget. Feed JoinHandles live on
the Executor (procsub_feed_handles, pruned at the next spawn), and
drain_procsub_feeds joins them at every end of the executor's
process lifetime: Executor::drop (ahead of the process-exit early
return — the payload is observable outside the dying process,
unlike the environment), the exec builtin's image replacement, and
the nofork tail replacement. Joining completes only the shell's own
transfer (payload in the pipe or consumer gone); the consumer keeps
running detached exactly like GNU's async child, so the rubash#1220
async contract is unchanged (slow consumer, shell exits in ~0.02s,
payload still delivered). A >64KB payload is now delivered in full
instead of truncating at the pipe buffer the abandoned thread had
filled.

Regression pins: tests/issue2179_procsub_exit_feed_regressions.rs —
both victim shapes x30 repetitions (pre-fix pass rates make 30
consecutive passes unreachable by timing luck), exec-replacement and
tail-replacement guards, and full delivery of a 588895-byte payload.
The victim pins themselves are untouched: the product fix makes them
pass as written (200 consecutive runs each, see REPORT).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 30, 2026 07:58
@caomengxuan666
caomengxuan666 merged commit 36dfeff into master Oct 30, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2179-procsub-exit-feed branch October 30, 2026 07:59
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