Repository navigation
WIP: fix pipeline-stage output procsub delivery (rubash#2184) - #2194
Merged
Merged
Conversation
…node so redirect-position procsub carriers receive the payload (rubash#2184) A `>(...)` redirect on a pipeline stage delivered zero bytes deterministically: materialization rewrote the target into an empty temp carrier and the consumer spawned at stage end read it, but the stage runners capture the stage's streams as strings and the driver loop's routing walk re-resolved the ORIGINAL node's redirects — writing the payload into a literal file named after the raw `>(...)` text while the consumer read the empty carrier. GNU has no capture-and-relocate step: subst.c:6362 process_substitute() creates the substitution pipe at expansion time and execute_cmd.c:2620 execute_pipeline() runs each element with its own redirections applied, so the element's redirected fd is the pipe. Fix: in execute_pipeline_stage, when materialization rewrote a redirect target into a carrier, route the captured streams through the MATERIALIZED node's redirect state (the driver's own ordered walk) before finish_process_substitutions spawns the consumer, and mark the stage pre-wired so the driver skips its original-node walk. The routing population is exactly the driver's: function and compound stages and the external shared-file arm place their own streams and are left untouched. Pins: tests/issue2184_pipeline_stage_procsub_regressions.rs (16) — last/middle/first stage, append form, builtin/function/compound stages, extra redirects, word+redirect procsubs on one stage, dup-before, stderr face, >64KiB payload, input-procsub boundary guards, no literal `>(...)` file, consumer-file delivery, external-stage stderr delivery. Expectations verified against GNU bash 5.3.20. Refs #2184
caomengxuan666
marked this pull request as ready for review
October 30, 2026 08:56
This was referenced Oct 30, 2026
This was referenced Oct 30, 2026
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.
Refs #2184
Defect
echo hi | cat > >(wc -c)printed0deterministically (GNU bash 5.3.20:3). An output process substitution in redirect position on ANY pipeline stage delivered zero bytes at any payload size, while the same redirect on a simple command worked.Localization
command_with_process_substitution_files) did run for stages: the empty carrier was created, the target rewritten, andfinish_process_substitutionsdid spawn the consumer — which read the still-empty carrier (side-effect probe: the consumer body ran).>(wc -c)resolved to a literal path: the payload was written into a file literally named>(wc -c)in the cwd (found on disk after the probe run), or the open failed ENOENT when the body contained/, producing a spurious diagnostic.execute_pipeline_stage) before the driver routes, so no driver-side fix could be in time.GNU shape:
subst.c:6362 process_substitute()creates the pipe at expansion;execute_cmd.c:2620 execute_pipeline()runs each element with its own redirections applied — no capture-and-relocate step exists.Fix (
src/executor/pipeline_exec.rsonly)In
execute_pipeline_stage's materialization branch: if a redirect target was rewritten into a carrier (new helperstage_redirect_rewritten_to_carriercompares the original vs materialized node), route the captured streams through the materialized node's redirect state with the driver's own ordered walk (route_pipeline_stage_streams) before the consumer spawns, and mark the stagepipeline_stage_fds_pre_wiredso the driver skips its original-node walk. The routing population is exactly the driver's: stages that place their own streams (function stages, compound stages, the external shared-file arm) are skipped — routing them would truncate their carrier with their empty captured strings.Input procsub on stages was probed as the boundary: it already worked (sources complete at materialization) and is pinned as a guard.
Verification
tests/issue2184_pipeline_stage_procsub_regressions.rs: 16/16 (last/middle/first stage, append, builtin/function/compound stages, extra redirects, word+redirect on one stage,2>&1-before, stderr face, 108890-byte payload, input boundary, no-literal-file, consumer-file, external stderr).>(wc -c)file is created anymore.Recorded, deliberately NOT fixed here (pre-existing, reproduce identically on simple commands — details in the cluster REPORT)
> >(X) 2>&1(dup ONTO a carrier) loses the payload on every path; reverse order works and is pinned.> >(X) > file,> file > >(X)): GNU's consumer inherits the fd state as of its position in the redirect sequence; rubash's consumer spawn does not model that on any path.3> >(wc -c)): consumer output missing on every path.cat >(wc -c)as a stage argument errors on the /dev/fd word (different mechanism, fd-word lifetime).No changes to
src/executor/dev_fd_operands.rsortests/regression.rs; no fifo protocol bytes touched.