Skip to content

fix(executor): stream input process substitutions instead of materializing (#1952) - #1954

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/issue1952-procsub-streaming
Oct 28, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/issue1952-procsub-streaming

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP — RC-freeze exception fix for the A-F1 audit finding.

Fixes #1952

Problem

Input process substitution materialized the producer's whole output in-process (src/executor/read_io.rs process_substitution_output_bytes_timed) before any consumer bound, so a non-terminating producer starved every consumer: cat <(echo x; sleep 20) printed nothing until EOF, while read … done < <(tail -f …) never iterated, head -1 <(…) | cat hung. GNU process_substitute (subst.c:6362) forks the body onto a pipe and hands over the read end at once.

Fix (mechanism only)

  • Every input-procsub binding site now spawns the real child the exec form already used (rubash#1021) and binds the pipe read end: standalone/command word forms, redirect targets, assignment values, command fd 0 / numbered redirects, the read builtin's scratch serve. Synchronous collection remains as fallback when a spawn cannot be set up.
  • The in-process cat streams a live pipe operand chunk-wise as bytes arrive (GNU cat.c byte-copy loop), through a single output sink kept to the finish emit.
  • `` names the real producer: wait collects its true status; the boundary reap spends a one-shot bounded grace (5 ms) on streamed producers so `kill -0` is deterministic once EOF was delivered (jobs.c:3064 `wait_for` parity, rubash#1022).

Pins

tests/regression.rs mod issue_1952: redirect-loop / cat-argument / pipeline streaming shapes (bounded producer; a flag file orders arrival against producer exit — all three fail on master), the exec 3< control, and ``/wait/`kill -0` parity.

Gates (lib baseline name-comparison, full regression, diffcorpus 306, -D warnings check) are being run on this branch; results land in the batch report. Do not merge — CI is the merge gate.

…izing (rubash#1952)

GNU process_substitute (subst.c:6362) forks the body onto a pipe and
hands the consumer the read end immediately; rubash collected the
whole body output in-process (executor/read_io.rs
process_substitution_output_bytes_timed) before any consumer bound,
so a non-terminating producer starved every consumer (RC audit A-F1:
`cat <(echo x; sleep 20)` printed nothing until EOF; `while read …
done < <(tail -f …)` never iterated).

Route every input-procsub binding site through the real-child spawn
the exec form already used (rubash#1021): standalone and command word
forms, redirect targets, assignment values, command fd 0 / numbered
redirects, and the read builtin's scratch serve; collection stays as
the fallback when the spawn cannot be set up. The in-process cat
streams a live pipe operand chunk-wise as bytes arrive (GNU cat.c's
byte-copy loop over the dup'd descriptor), through one output sink
kept to the finish emit. $! names the real producer: `wait` collects
its real status, and the boundary reap spends a one-shot bounded
grace (5 ms) on streamed producers so `kill -0` is deterministic
once EOF was delivered (jobs.c:3064 wait_for reaps while blocked;
rubash#1022 parity).

Regression pins: tests/regression.rs mod issue_1952 — redirect-loop,
cat-argument and pipeline streaming shapes (bounded producer, flag
file orders arrival against producer exit), the exec 3< control, and
$!/wait/kill -0 parity.
…ildren (rubash#1952)

Two serve paths still assumed the collected endpoint kind:

- materialize_dev_fd_operands backed only buffered (Text /
  ProcessSubstitution) endpoints with a fed pipe for external
  children and skipped File endpoints as "natively resolvable" —
  but the descriptor lives in this process only, so `$(cat <(…))`
  and external argv delivery of a streamed word failed ENOENT in
  the child. Pin a dup of the File endpoint's handle at the
  operand's number through the same attach machinery (shared
  offset, not consumed — the GNU fork contract).
- The comsub quick-read ladder ($( < /dev/fd/N )) served only the
  buffered snapshot; a streamed endpoint fell through to an fs
  read of the literal path. Drain the File endpoint through the
  shared handle (fd_table::read_file_endpoint_bytes, the &self
  counterpart of read_all_bytes).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Gate results on this branch (Linux, this machine; full detail in the batch report):

  • cargo check with -D warnings: clean.
  • Lib tests: 904 pass / 1 fail / 3 ignored — failure set name-identical to the pristine 842e0e2 baseline (sole failure: ownership_unary_operators_check_existing_file, pre-existing).
  • tests/regression.rs: 172 pass / 4 fail — the 4 failures are name-identical to pristine (eco-completion readdir order, issue_759 case_2, win_face 1887/1888); the 5 new issue1952 pins pass, and the 3 streaming pins fail on master by construction (flag-file discrimination verified against the tip binary).
  • 27 adjacent procsub/cat/pipeline test files: 24 fully green; remaining failures name-identical to pristine (issue438 argv_word_stays_gnu_dev_fd_form, issue1219 exit ordering race, cat_redirect_stream niu.exe-environment failures).
  • diffcorpus 306: 305 pass; sole failure ps06 adjudicated a race flake (same-window distributions: tip 10/10 wn=1, this branch 9/10, GNU 3/4 — the oracle draw flips).
  • Audit probes f1a–f1d re-run on the final binary: all stream (f1c bytes visible at 3s while the producer still sleeps).
  • [bug] procsub 端点逐行读约 0.29ms/行常数税:150k 行 42.9s vs GNU 1.35s(线性大常数,非二次方) #1951 note: the per-line read tax dropped ~1/3 with streaming (0.38–0.40 → 0.26–0.28 ms/line, same-window); the remainder is the read machinery, out of this batch's scope.

Two follow-up commits beyond the first push were needed for external-child delivery of streamed endpoints (materialize attach + comsub quick-read drain) — both are in the branch.

…ows external-word drain)

The pipeline-head streaming pin (issue1952_pipeline_head_streams_first_line)
fails deterministically on Windows CI: a process substitution delivered as
an argv word to a spawned external child is drained to a temp file before
spawn (dev_fd_table_operand File arm -> drain_handle_to_temp), so the
consumer cannot see line 1 until the producer exits. Live delivery to
external children needs the rendezvous endpoint tracked as rubash#1959
(#1903 / unified-layer S6 design piece); the in-process consumer forms
stream on Windows already.

Keep the GNU assertion verbatim, add #[ignore] citing #1959 per repo
convention; remove the ignore when the #1959 endpoint lands.
Root-cause chain: fix-1952 REPORT section 7.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 28, 2026 12:27
@caomengxuan666
caomengxuan666 merged commit fa17033 into master Oct 28, 2026
15 of 16 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/issue1952-procsub-streaming branch October 30, 2026 01:41
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.

[bug] procsub 全量物化:生产者不终止则消费者永不启动(while read / cat 参数形 / 管道内形挂死,GNU 流式)

1 participant