Repository navigation
WIP: fix(executor): complete output-procsub feeds before the process lifetime ends (#2179) - #2182
Merged
Merged
Conversation
…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).
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.
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 -cchild 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 beforemain()joined the shell thread and calledstd::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:
JoinHandles live on theExecutor(procsub_feed_handles, finished handles pruned at the next spawn).drain_procsub_feedsjoins 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);execbuiltin's image replacement (both dispatcher sites);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
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.process_substitutionmodule, issue1220/1221 async/write-once pins, issue1659/2053/2057 families).Adjacency
No changes to
src/executor/dev_fd_operands.rsortests/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.