Repository navigation
WIP: design+fix: ambient Text endpoints for concurrent pipeline spawners (#2308) - #2331
Merged
Merged
Conversation
GNU materializes a heredoc body once (redir.c:423 here_document_to_fd) and every forked pipeline element inherits the descriptor through the same do_redirections walk (redir.c:237; execute_cmd.c:2620 execute_pipeline). #2292 taught the sequential spawn faces to materialize ambient Text endpoints, but the concurrent pipeline spawn loops only registered the handle-backed ambient pins (attach_ambient_fd_pins) — a Text endpoint has no handle to pin, no env stamp was made and no carrier materialized, so a stage spawned in the concurrent burst read EBADF on every ambient heredoc descriptor. New attach_ambient_text_delivery (external_inner.rs) runs the existing deliver_ambient_text_endpoints pass for a hand-built stage process — same slot selection and skip rules, no second copy — registers its pins as an additional pre_exec closure, and returns the parent-side duplicates. All four concurrent spawn loops in pipeline_exec.rs (spawn_wait_concurrent_external_stages, run_shell_writer_pipeline, execute_external_prefix_streaming_tail, the non-Windows execute_external_pipeline_concurrently) call it beside attach_ambient_fd_pins and close the dups once their spawn resolves — the apply_external_fd_delivery lifetime contract. The carrier files keep living in procsub_adhoc_carriers until finish_process_substitutions, after every stage of the pipeline has been reaped; the only per-stage artifact is the dup, whose required lifetime is exactly the one spawn. Pins: tests/issue2308_concurrent_text_delivery_regressions.rs (8 — one-reader stage, group-wrapped pipeline, two stages on one heredoc, stage+grandchild, writer-pipeline consumer, mixed File+Text ambient, last-stage reader, prefix + brace-group tail). Controls: issue2292 18/18, issue2235 11/11, lib 985/985, regression 221 passed + the 6 stock local reds. Refs #2308
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 #2308. Design + fix, ready for harvest review (cluster REPORT in the workdir has the full design, probe tables and run ledger).
Design (one paragraph)
Three resources, three owners: the carrier file already lives long enough (registered in
procsub_adhoc_carriers, unlinked atfinish_process_substitutions— after every pipeline stage is reaped); the parent-side inheritable dup must live from materialization until that stage'sspawn()resolves (the sequential face'sapply_external_fd_deliverycontract); the actual gap was that the concurrent spawn loops never ran the Text pass at all —attach_ambient_fd_pinscan only carry handle-backed endpoints, and a heredoc body has no handle. GNU ground: the body is materialized once (redir.c:423 here_document_to_fd) and every forked pipeline element inherits the descriptor (redir.c:237 do_redirections;execute_cmd.c:2620 execute_pipeline). The fix is contained in the current spawner architecture — no #2234-class carrier rework is needed.What changed
external_inner.rs: newattach_ambient_text_delivery— runs the existingdeliver_ambient_text_endpointsverbatim (same slot selection/skip rules), registers its pins as an additionalpre_execclosure, returns the parent-side dups.pipeline_exec.rs: all four concurrent spawn loops (spawn_wait_concurrent_external_stages,run_shell_writer_pipeline,execute_external_prefix_streaming_tail, non-Windowsexecute_external_pipeline_concurrently) call it besideattach_ambient_fd_pinsand close the dups right after their spawn resolves. On Windows the concurrent faces gain the env-stamp channel the sequential face already had.tests/issue2308_concurrent_text_delivery_regressions.rs: 8 pins (one-reader stage, group-wrapped pipeline, two stages on one heredoc, stage+grandchild, writer-pipeline consumer, mixed File+Text ambient on one stage, last-stage reader, prefix + brace-group tail).Per-stage snapshot carriers are the standing #2272/#2292 delivery model (a child's reads don't advance the parent's offset); GNU's concurrent readers of one shared description race on the offset, so no deterministic behavior depends on sharing one carrier.
Verification (scrubbed-fd batches, CARGO_BUILD_JOBS=1)
cargo checkclean; rustfmt clean on touched files.Residual found (separate bug, not this PR)
A rubash child inheriting two or more ambient heredoc carriers gets them crossed in its startup restore (its fd 3 serves the last carrier's body; parent delivery itself is proven correct via a foreign python3 witness). Reproduces with no pipeline at all on the sequential face, and this diff can't reach that path (additive-only in external_inner.rs) — pre-existing on master. Full evidence + reproducers in the cluster REPORT (residual R1), ready to file separately.