Skip to content

fix(executor): sandwich function-stage procsub pipeline stream loss (Refs #3149) - #3177

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3149-junit-tap13-leak
Nov 9, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3149-junit-tap13-leak

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

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). New ProcsubSpawnFd::StreamWrite disposition: 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)

  • Pin tests/issue3149_junit_nested_tap13_leak.rs: base 2/1 (01 red, total stream loss) → head 3/3 green.
  • Probes B–Q under the head binary: all green, byte-identical to GNU 5.3.20 where applicable.
  • Lib bilateral: base 1206/0/4 = head 1206/0/4 (zero regression).
  • Neighbours (8 stems): 7/8 green; issue2398_jobstop_regressions fails 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: issue2124 connections, issue2933 stdout, issue2722 dir, issue2500 script, issue2584 mut) — not a regression; needs a separate test-hygiene cleanup.
  • Full-file junit-formatter.bats ecosuite 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)。

…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 caomengxuan666 changed the title test: pin sandwich function-stage procsub pipeline stream loss (Refs #3149) fix(executor): sandwich function-stage procsub pipeline stream loss (Refs #3149) Nov 9, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 9, 2026 14:02
@caomengxuan666
caomengxuan666 merged commit 9ef7380 into master Nov 9, 2026
11 checks passed
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
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.

bats junit-formatter: nested fixture-suite tap13 lines leak into outer TAP stream in full-file runs (Executed 15 instead of 13, rc=1)

1 participant