Skip to content

WIP: procsub drain faces — varredir_close completion close (#1646) + endpoint read tax (#1951) - #2017

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/procsub-drain-1951-1646
Oct 29, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/procsub-drain-1951-1646

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Two process-substitution drain faces, one commit per issue. Full evidence: cluster REPORT (fix-procsub-drain).

#1646 (commit f5a3d82) — FIXED. sharper than filed: the exit drain itself is complete on current master (finish_shell sweep delivers byte-exact output across -c/stdin/script/exit-builtin/EXIT-trap routes, md5-verified vs GNU 5.3.20). The live data-loss: with shopt -s varredir_close, a {var} descriptor was closed at redirect-APPLICATION time instead of at the owning command's completion (GNU redir.c:976-985 only registers add_undo_close_redirect at application; the close runs with undo_redirections at command end). The command's own >&$var write was rejected EBADF — a >(...) consumer's stream lost wholesale; a plain-file target left the command at rc=1 with an empty file. Fix: record at application (Executor::deferred_varredir_closes), drain at the execute_command bracket with watermark discipline; skip numbers an external dispatch already closed/recycled. Pins: tests/regression.rs mod issue_1646 (4 tests, GNU 5.3.20 expectations).

#1951 (commit 1ccdd9e, pins only) — re-measurement verdict: the endpoint-specific tax is GONE; no endpoint mechanism fix remains. Measured per the issue's own protocol (release, Linux, same machine, interleaved): procsub while-read now runs at 3.2x GNU — the BEST relative face among read shapes — tracking the engine's general per-command floor, not an endpoint tax (the audit-era 32x was the materialized endpoint replaced by #1952 streaming + F5 #1914; the issue itself prescribed re-measuring after streaming). Endpoint drains at external-cat speed (0.7us/line); the read premium is source-independent (file/pipe/procsub within noise). GNU reads pipes byte-wise BY DESIGN (read.def:668 unbuffered_read for pipe input; zreadc buffering is the file face, where rubash already buffers) — buffering pipes would diverge from GNU and break fd sharing. Residual homes: floor tax = #682, while-read shape = #2005. Two pins guard the re-measured face (exact 20k count; whole ordered records).

CI: all green except the niubash canary's ledger-cmp step (known transitional red — niu-side v4 sync rides niubash#668; this branch does not touch the ledger).

Fixes #1646

… not at application (rubash#1646)

GNU redir.c do_redirection_internal (redir.c:976-985): with
REDIR_VARASSIGN and the varredir_close shopt (builtins/shopt.def:269
varassign_redir_autoclose), the descriptor is only REGISTERED for
closing at application time via add_undo_close_redirect -- the close
itself happens when undo_redirections runs at the owning command's
end. rubash closed inline inside execute_dynamic_fd_var_redirect, so
the owning command's own >&$var write was rejected with EBADF: the
data never reached the descriptor at all. For a >(consumer) stream
the whole payload was silently lost; for a plain file the command
failed with rc=1 and an empty target.

Record the fd in Executor::deferred_varredir_closes at application
time instead (redirection and heredoc forms alike), and drain the
records a command added from execute_command -- the per-command
bracket -- with watermark discipline so nested commands keep their
own closes. A descriptor an external command's undo already closed
during dispatch is skipped, so a recycled number is never closed by
mistake; drain errors are swallowed like the shell-exit sweep's,
since a procsub body's status never fails its owning command.

Exit-path drain itself was verified complete before this change
(the rubash#1336 sweep): -c, stdin, script-file, exit-builtin and
EXIT-trap routes all deliver the accumulated stream byte-exact;
the remaining delta this commit removes is the application-time
close. Regression pins in tests/regression.rs (mod issue_1646):
varredir_close procsub + plain-file survival, persistent
drain-at-exit, default-mode accumulation.
…#1951)

Re-measurement verdict for the #1951 constant tax (full data in the
cluster report): the ~0.29ms/line endpoint-specific tax measured at
the audit freeze tip is gone on current master -- the streamed
endpoint landed by rubash#1952 plus the F5 work (PR #1914) replaced
the materialized endpoint it lived on. Same-window decomposition
(Linux, same machine) now shows the while-read face tracking the
engine's general per-command floor: the endpoint drains at external
cat speed, and the shell-side read premium is source-independent
(regular file, pipe and procsub within noise of each other). GNU's
own pipe reads are byte-wise by design (read.def:668 sets
unbuffered_read for pipe input; zreadc buffering covers the file
face, where rubash already buffers), so no endpoint mechanism fix
remains that would not either duplicate the floor-tax work tracked
by rubash#682 / rubash#2005 or diverge from GNU.

These two pins guard the re-measured face in CI: exact line count
at 20k lines and whole, ordered records off the streamed endpoint.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 01:13
@caomengxuan666
caomengxuan666 merged commit 49b15ab into master Oct 29, 2026
8 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/procsub-drain-1951-1646 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] Follow-up to #1359: write-procsub consumer data lost at script exit (GNU drains it)

1 participant