Repository navigation
fix(executor): stream an unbounded external producer into an in-shell pipeline tail (#761) - #784
Merged
Conversation
… pipeline tail (#761) `yes | true` (and `yes | :`, `yes | read -r l`, `yes | cat | true`) never returned: the shell drained the producer into memory (~250 MB/s) instead of closing the read end and letting it die of SIGPIPE. Reproduces on HEAD; the same absence is the untested root of #723's `producer | in-shell-tail` freeze (its 190-run negative matrix never used an inline-arm / builtin LAST stage). Root cause (interleaving): the rightmost element was never started until the sequential stage loop had materialized every upstream element's whole stdout (`execute_external_pipeline_stage_inner` -> `child.wait_with_output`, pipeline_stages.rs). An unbounded producer never reaches EOF, so the tail's read end was never closed and the producer never observed a termination — the shell, not the producer, was the side that grew. The materializing `execute_external_prefix_concurrently` path had the identical defect one level up: `spawn_wait_concurrent_external_stages` drains the last prefix member to completion before the tail starts, so `yes | cat | true` still never terminated. Fix: `execute_external_prefix_streaming_tail` (pipeline_exec.rs) runs the plain-external prefix on real OS pipes and hands the LAST pipe's read end to the in-shell tail as fd 0 (`pipeline_stdin_stream`, mirroring #345's `pipeline_stdout_stream`). The tail's readers (`read`, a compound body's `read`/`mapfile`) pull the live pipe through the fd table (read_io.rs read_file_bytes blocks on the handle), because the stage dispatcher leaves FUNCTION_STDIN absent for a streaming tail (pipeline_exec.rs / pipeline_stages.rs, `execute_builtin_pipeline_stage` and `execute_compound_pipeline_stage`). When the tail stops reading — it exits, or reads one record, or `break`s — restoring fd 0 closes the read end to the producers, and each lingering member is reaped through `wait_for_windows_pipeline_member` with the SIGPIPE-shaped 141. Admission is a whitelist (plain stages; the tail a literal `true`/`:`/`false`/`echo`/ `printf`/`read` or a compound body), so any shape this path cannot faithfully stream keeps the existing executor. GNU anchor: execute_cmd.c:2620 execute_pipeline forks every element on pipe(2); the rightmost element's exit closes its read end and the writer dies of SIGPIPE (`yes | true` -> PIPESTATUS 141 0). Measured (debug, this box), bounded by `timeout`: - `yes | true` before rc=124 @5.2 s; after rc=0 @0.1 s, PIPESTATUS 141,0 - `yes | :` before rc=124 @5.2 s; after rc=0 @0.1 s - `yes | read -r l` before rc=124 @5.2 s; after rc=0 @0.1 s - `yes | cat | true` before rc=124 @5.2 s; after rc=0 @0.1 s - `seq 1 100000000 | true` before rc=124 @8.2 s; after rc=0 @0.2 s - `yes | head -1` unchanged rc=0 @0.1 s (negative control) Tests: tests/issue761_pipeline_unbounded_producer.rs (deadline-guarded, sandboxed CWD). Existing issue345_shell_writer_sigpipe, issue382_hardkilled_lingerer_sigpipe_status, issue158_pipeline_drain_deadlock, issue429_pipeline_stdin_redirect_regressions and `--lib` stay green.
This was referenced Oct 19, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 20, 2026
The four reproductions were committed #[ignore]d while the defect was live; PR #784 fixed it and they now pass in ~0.7 s (they previously hit the 10 s bound), so remove the attributes and let them enforce the behaviour. Also promote lim-f5-fd-cap to must-match: the 2026-10-20 catalogue run (arm 62a30ab) reported PROMOTE for it, i.e. the fd table no longer caps at 1014.
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
Fixes #761. An unbounded external producer feeding a pipeline whose rightmost stage is served in-shell (a builtin / inline arm such as
true/:/echo/read, or a compound body) no longer hangs:yes | true(andyes | :,yes | read -r l,yes | cat | true,seq 1 100000000 | true,yes | while read; do break; done) return in well under a second withPIPESTATUS[0]=141.This is very likely the reproducible root of the older #723 freeze (
yes | head -5 | while read …) that could not be reproduced in 190+ attempts across 13 shapes — none of those shapes used an inline-arm / builtin last stage, which is the trigger. See the #723 link at the bottom.Root cause (interleaving, with file:line)
The rightmost element was never started until the sequential stage loop had materialized every upstream element's whole stdout:
execute_simple_pipeline(src/executor/pipeline_exec.rs) walks stages one at a time; stage 0 ofyes | trueis externalyes, dispatched toexecute_external_pipeline_stage_inner(src/executor/pipeline_stages.rs), which ends inchild.wait_with_output()—read_to_endonyes's stdout.yesis unbounded, so that read never returns;true(the tail) is never reached; its read end is never closed;yesnever observes a termination.The
#206materializing prefix path has the identical defect one level up:execute_external_prefix_concurrently(pipeline_exec.rs:2023 at base) declinesprefix_len < 2(so a one-external prefix falls to the sequential drag) and when it does run it collects the last prefix member to completion viaspawn_wait_concurrent_external_stages→results.last().cloned().yes | cat | truetherefore drainscat's output in a drain thread beforetrueever starts.GNU anchor
execute_cmd.c:2620 execute_pipelineforks every element on realpipe(2)s. The rightmost element's exit closes its read end; the writer dies of SIGPIPE.yes | true→PIPESTATUS=(141 0), rc 0. (Same absence as #345, from the opposite end: #345 is a shell-side writer; this is an external producer with a shell-side reader.)Fix
execute_external_prefix_streaming_tail(new, src/executor/pipeline_exec.rs, Windows) runs the plain-external prefix on real OS pipes and hands the last pipe's read end to the in-shell tail as fd 0, via a newpipeline_stdin_streamexecutor field that mirrors #345'spipeline_stdout_stream:FUNCTION_STDINabsent for a streaming tail, so a present-but-empty mirror cannot short-circuitreadback to EOF (read_io.rs:361-363); the tail's readers (read, a compound body'sread/mapfile) pull the live pipe through the fd table (read_file_bytesblocks on the handle).breaks), restoring fd 0 drops theFileFd→close_handle→ the producers' next write is a broken pipe.wait_for_windows_pipeline_memberwith the SIGPIPE-shaped 141 (lingerer_sigpipe_status).true/:/false/echo/printf/read, or a compound body). Any shape this path cannot faithfully stream keeps the existing executor. Nested pipelines clear the flag (execute_simple_pipelinewrapper), so a body's inner pipelines are unaffected.No sleeps, retries, timers, or CFG hints.
Before / after (this box, debug binary,
timeout-bounded)yes | trueyes | :yes | read -r lyes | cat | trueseq 1 100000000 | trueyes | while read; do break; doneyes | head -1(negative control)Peak-RSS sampling of the pre-fix shell for
yes | true: 522 MB → 1034 MB in ~3 s whileyes.exestayed at 7.4 MB — confirming the consumer, not the producer, was growing.* The intermediate
catstatus 0 vs GNU 141 is the pre-existing Windows intermediate-SIGPIPE gap (identical for the untouched all-external path:yes | cat | head -1→PS=141,0,0). Not introduced here;PIPESTATUS[0]is 141 as required.Tests
tests/issue761_pipeline_unbounded_producer.rs: deadline-guarded (20 s), sandboxed CWD, resolves real externals — coverstrue/:/false/read/echo/printftails,yes | cat | true, the compoundwhile … breakand brace-group tails, thePIPESTATUS=141,0contract, theseq 1 1e8 | truelong case, and theyes | head -1negative control. Verified to fail (timeout) on pre-fix master and pass after.issue345_shell_writer_sigpipe,issue382_hardkilled_lingerer_sigpipe_status,issue158_pipeline_drain_deadlock,issue429_pipeline_stdin_redirect_regressions,--lib(689), plus a ~70-file pipeline/read/compound sweep.The two sweep failures (
issue680_mapfile_encoded_split_regressions::mapfile_nul_delim_stays_on_decode_path,issue647_function_redirect_stdin_regressions::function_call_file_redirect_survives_external_spawn) are pre-existing Windows path-quoting test bugs: both fail identically on cleanorigin/master(confirmed by stashing this change).Relation to #723
#723 could not reproduce because its 13 shapes all used a bounded or external LAST stage. The missing shape is exactly this one — an unbounded external producer with an in-shell last stage (
| true,| :,| read,| while … break). This PR reproduces it deterministically and fixes it at the pipe-ownership layer, which is the root cause #723 was hunting. /cc #723.