Repository navigation
fix(executor): sandwich function-stage procsub pipeline stream loss (Refs #3149) - #3177
Merged
Merged
Conversation
…3149) bats junit-formatter's nested fixture-suite tap13 lines leak into the outer TAP stream in full-file runs (Executed 15 instead of 13, rc=1). Reduced: producer | mid | cat with mid() { exec 3<&1; tee >(cat >&3) | cat > report.txt; } loses the whole stream on the base — tee is spawned on a fresh empty pipe instead of the live inter-stage pipe (GNU execute_cmd.c:2620/6373 do_piping dup2). Root cause (REPORT.md §2): the streaming-sandwich path binds the function stage's fd 0 to a File endpoint over the live producer-pipe read handle, but the sequential external-stage spawner models stdin only as inherit-or-payload-string and drops the live_stdin fact, so the procsub-carrying inner pipeline's stage-0 tee reads immediate EOF. Refs #3149
…3149) A stage-0 fd 0 the pipeline wrapper left bound is a LIVE pipe read end (the streaming sandwich's producer pipe). Re-read it from the fd table at the spawn point and hand the child a duplicate of it, instead of feeding the empty staged payload through a fresh pipe that EOFs at once (GNU execute_cmd.c:6373 do_piping: the pipe replaces fd 0). The dev-fd operands then materialize against the fd table, as for an inherited stdin. A computed payload is never discarded (the guard is unreachable on the live path). Refs #3149
…3149) When the live capture frame streams to a pipeline pipe, a `>(...)` consumer whose fd names the capture scope must hold a duplicate of the stream's write end itself (the stage pipe), not the BG_CAPTURE ordering pipe: GNU subst.c:6362 process_substitute forks inherit the descriptor, and execute_cmd.c:6373 do_piping replaces fd 1 with the pipe. The consumer's bytes then stream live to the downstream member instead of landing in a frame buffer the sandwich driver discards when the last member is a process. The new StreamWrite disposition is never registered as a BackgroundCapture writer and never drained; with no stream armed (plain $(...) capture) the BG_CAPTURE route stays the answer (rubash#2484). Refs #3149
caomengxuan666
marked this pull request as ready for review
November 9, 2026 14:02
caomengxuan666
added a commit
that referenced
this pull request
Nov 20, 2026
…3982) PR #3530 (for #3487) threaded pre-rendered FunctionSetViews through the set/declare funnels, and the executor materialized them at every dispatch: Executor::function_set_views() rendered every function's listing text via ast_print on each set/declare/typeset/local call, although only the bare-listing arm ever prints them. In a function-heavy shell (bats loads ~150 library functions and calls `local` pervasively) that is an O(total definition text) tax per call: on X299 (release) 2,000 local-carrying calls under 150 twelve-line functions took ~33 s, and bats' junit gather reported 221 ms/test against ~35 ms before the regression (bisect over 9ef7380..81a5bbf: first bad 3505855, the #3530 commit itself; #3177 is clean). GNU renders function definitions only inside print_all_shell_variables' print_func_list arm (builtins/set.def:506-527; variables.c:1079-1090), reached solely from the no-operand listing. Mirror that cost shape: the funnels now take a lazy FunctionSetViewProvider and realize the views only in the listing arm (set with no args; declare's plain arm). The render itself (Executor::render_function_set_views over the functions and function_def_infos maps) is unchanged. What this change deletes: the eager per-dispatch full-table render at five executor call sites (execute_set and the four declare/local routes in declare_local.rs). Verification (X299, release build of this branch): - probe (150 functions x 12 lines, local-loop x2000): 33 s -> 1 s - bats junit suite, direct form: 221/216 ms per test -> 37/37 ms (pre-#3177: 34/36 ms; #3177 itself: 35/37 ms) - bats junit outer form: 43 s -> 17 s wall, 9/9 ok (#3177: 17 s) - listing outputs (bare declare/set/typeset, -F/-f/-p/-a forms, POSIX mode, bare local, declare --) byte-identical to master except the self-referential BASH=<exe path> lines - new pin tests/issue3230_declare_family_lazy_views_regressions.rs (scaling-ratio sentinel + listing-arm checks): 2/2 green; issue3487 pin 9/9 green; builtins::set/declare lib tests 16/16 UNVERIFIED-BY-CAPTAIN
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.
Two fixes for the sandwich function-stage procsub pipeline stream loss (bats junit-formatter nested tap13 leak, #3149).
Fix 1 — live fd 0 for sequential stages (
src/executor/pipeline_stages.rs,ca171fda)A stage-0 fd 0 the pipeline wrapper left bound is a LIVE pipe read end (the streaming sandwich's producer pipe). Re-read it from the fd table at the spawn point and hand the child a duplicate of it, instead of feeding the empty staged payload through a fresh pipe that EOFs at once (GNU execute_cmd.c:6373 do_piping: the pipe replaces fd 0). A computed payload is never discarded.
Fix 2 — procsub consumer gets the live capture stream (
src/executor/external_setup.rs+src/executor/trap_exec.rs,8b4a6336)When the live capture frame streams to a pipeline pipe, a
>(...)consumer whose fd names the capture scope holds a duplicate of the stream's write end itself (the stage pipe), not the BG_CAPTURE ordering pipe (GNU subst.c:6362 process_substitute; execute_cmd.c:6373 do_piping). NewProcsubSpawnFd::StreamWritedisposition: never registered as a BackgroundCapture writer, never drained; with no stream armed (plain $(...) capture) the BG_CAPTURE route stays the answer (rubash#2484).Verification (lane-run, base f17644d)
tests/issue3149_junit_nested_tap13_leak.rs: base 2/1 (01 red, total stream loss) → head 3/3 green.issue2398_jobstop_regressionsfails identically on base (pre-existing, not a regression).RUSTFLAGS="-D warnings"check fails on head AND base with pre-existing dead-code/lint debt in test files (five different first-errors across runs: issue2124connections, issue2933stdout, issue2722dir, issue2500script, issue2584 mut) — not a regression; needs a separate test-hygiene cleanup.junit-formatter.batsecosuite rerun (900s): head still 15 instead of 13, rc=1 — the file's remaining leak is a distinct residual mechanism (raw TAP13 lines reach the outer TAP stream via the ambient fd 3 in the reentrant context; the direct nested run is identical GNU vs rubash). Filed as rubash junit-formatter.bats 仍报 15 instead of 13:嵌套 tap13 行经 ambient fd 3 泄漏(#3149 残余) #3221 (bug + gnu-baseline + area:fd, 1.5.1, gated on this PR merging). This PR does not close bats junit-formatter: nested fixture-suite tap13 lines leak into outer TAP stream in full-file runs (Executed 15 instead of 13, rc=1) #3149.Root cause, fix design, pin design and full per-leg numbers:
~/workspace/fix-3149/REPORT.md§2–§8.Refs #3149
本 PR 删除了什么
无(新增测试文件 + 两处修法;净 +324/−32:钉 +178、修法 1 +60/−29、修法 2 +86/−3)。