Repository navigation
fix(fd): stream procsub argv words to external children via the #1903 fifo-marker rendezvous (rubash#1959) - #2156
Merged
Merged
Conversation
…fifo-marker rendezvous (rubash#1959) Root cause (Windows face): a process substitution delivered as an argv WORD to an external child (`head -1 <(body)`, `$(cat <(body))`, the pipeline word form — every spawn site funnels through dev_fd_operands::materialize_dev_fd_operands -> dev_fd_table_operand) fell into the FdReadEndpoint::File arm, whose pipe-backed procsub endpoint (rubash#1952, display path "<(...)") has no filesystem path, so the parent drained the producer to EOF into a temp file BEFORE spawn: the consumer started only after the producer exited. GNU subst.c:6362 process_substitute hands the child the live pipe read end under /dev/fd/N — consumers read while the producer still runs. (The unix face already does this via unix_fd_attach.) Fix: deliver the live stream through the #1903 WinuxCmd FIFO-marker rendezvous — the same design piece the issue names. The argv word now carries an on-disk `!<fifo>` marker path; the child's own runtime bridges its open to the deterministic named pipe (reader = INBOUND server, WinuxCmd file_io.cppm open_fifo_read_handle), and a pump thread copies the procsub read end into it as the writer client (open_winux_fifo_write, GNU's blocking O_WRONLY fifo open). The pump owns a DuplicateHandle reference of the read end, so fd-table cleanup after the child exits cannot race its reads; closing the writer is the child's EOF, and a consumer gone early fails the pump's writes (the GNU SIGPIPE shape). Setup failure falls back to the previous drain-to-temp. Also: the rendezvous arm records NO consume-fd seek. The word fd is command-scoped (removed at this command's end), and a finish-time seek on the table's handle serializes against the pump's parked ReadFile on the same pipe file object — synchronous handles allow one operation at a time — so the shell blocked for the producer's whole remaining lifetime (observed 10s vs GNU 0s; probe head -c 7 <(printf 'first\nse'; sleep 10)). GNU 5.3.20 A/B (WSL script-file, 2026-10-29): byte-for-byte match on the pipeline word form, standalone word form, comsub external-cat form, byte-mode head form, the abandoned-producer boundary, producer crash (partial delivery + EOF), and the pipeline shape GNU itself answers late (cat <(…) | head -1). Pristine master drained all of them. Pins: tests/issue1959_procsub_argv_streaming.rs (6 tests: stage-word first bytes, abandoned-producer boundary, comsub full delivery + EOF, producer-sees-consumer midflight, producer crash, GNU wait shape), each gated on a round-trip probe that proves the resolved tools are marker/pipe-aware (self-skips where no protocol consumer exists). issue1952_pipeline_head_streams_first_line: the global #[ignore] is lifted (runs again on non-Windows, unchanged unix face); Windows keeps a cfg_attr ignore with the tool-side reasons — the suite's airtight PATH resolves an MSYS head that does not speak the marker rendezvous, and WinuxCmd#1442 tracks the head line-mode fifo-operand gap in the toolchain that does (external issue, not a rubash ledger line). Verification (CARGO_TARGET_DIR=D:/repo/nbbuild/pkg11/H6/target, release): cargo test --lib 1063 passed; --test regression identical 64-failure set to pristine master 8755dd7 (environmental: this machine's Git lives outside the harness's C:\Program Files\Git minimal-PATH probe — zero deltas from this change; the 1952 head pin shows as the one Windows ignore); --test cli_tests identical failure set to pristine except version_appends_build_metadata_after_the_gnu_ block_rubash_488, which reads the worktree git hash and fails only while the fix is uncommitted (green after commit); procsub/fifo family files issue1021/1184f4/1219/1220/1221/1223/1336/1460/1523 match pristine exactly; tests/issue1959_procsub_argv_streaming.rs 6/6 green (and 6/6 clean skips under a tool-less PATH). Commit hook disclosure: `cargo fmt --check` via the pre-commit hook fails on this machine with os error 206 (filename too long) — the known repo-wide precedent; rustfmt was run explicitly on the three touched files instead, and the commit is made with --no-verify for that reason only. Closes #1959 (Windows streaming face; the pinned acceptance forms are streaming-green, with the literal `head -1` word form's Windows runability blocked on WinuxCmd#1442 only).
This was referenced Oct 29, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 30, 2026
…ndle (rubash#2171) After `exec 0<dir`, a child that merely inspected the descriptor (`ls -l /proc/self/fd/0`) invalidated the parent's fd-0 FileFd: the next builtin read reported `Bad file descriptor` where GNU reports the descriptor's own `Is a directory` (read.def:911). Same death for any File endpoint on any fd (an exec-bound regular file on fd 3 died identically). Root cause, in the unix branch of materialize_dev_fd_operands: the attach record (DevOperandMaterialization) owns what it records — its Drop closes every recorded handle once the child exits, like GNU closing the parent's pipe end once the forked child owns its copy. Two of its three arms record fresh, owned handles (a capture-pipe read end, a just-opened procsub file). The File arm recorded the endpoint's OWN handle — the parent's live descriptor — so the record's drop closed the parent's FileFd under it; the fd-table entry survived but pointed at a dead handle. Fix: the File arm attaches a duplicate (crate::fd::duplicate_handle). A dup shares the open file description, offset included, so the child's /proc view and the #1952 shared-offset read face are unchanged (verified: a child reading through the operand behaves byte-identically to GNU before and after); the record now closes only its dup, and the parent's descriptor survives any number of inspecting children. Platform shape: the defect and the fix are unix-branch only. The Windows materialization never hands a child the parent handle — it rewrites the operand to the endpoint's path or a temp file, and its deferred consume step seeks (consume_all_text) rather than closes. The read-side EISDIR shape is #2101/#2167's and is not touched. Collision note: this is the cluster's only hunk in src/executor/dev_fd_operands.rs, which open PR #2156 also edits (its hunks are the drain/finish regions; this one is the unix materialize loop's File arm). The borrowed-handle invariant lives only in this file, so the hunk is minimal and flagged in the PR body for merge sequencing. Pins: tests/issue2171_proc_fd_operand_survival_regressions.rs (4 tests; 3 red on master, 1 guard green both ways). Refs #2171
This was referenced Oct 30, 2026
This was referenced Oct 30, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 2, 2026
…e fifo-marker route (#2473) GNU assembles multi-operand process substitutions per occurrence: expand_word_internal calls process_substitute for EVERY `<(...)` word (subst.c:11364-11385), each with its own pipe (subst.c:6381) under its own /dev/fd name (move_to_high_fd + make_dev_fd_filename, subst.c:6392-6394, add_fifo_list 6343) — the contract for every operand being that whatever consumer opens the name receives the producer's bytes. rubash#2225 gated the Windows fifo-marker streaming route on binary identity ("the consumer IS the WinuxCmd runtime, so its reads bridge markers"). Measured against the installed WinuxCmd 1.1.20 the prediction is false on the READ side: paste/wc/od/comm/diff read the 7 `!<fifo>` marker bytes plainly (`paste <(echo 1) <(echo x)` printed `!<fifo>\t!<fifo>`, `wc -c <(printf hello)` counted 7), and WinuxCmd's own runtime does not rendezvous with its own mkfifo marker — its `od` reads the marker bytes immediately while the writer blocks in the pipe open (unixwin/WinuxCmd#1493). A wrong identity prediction here is silent operand byte corruption, the exact harm #2225 was written to prevent, so identity is no longer treated as proof. The delivery gate now inverts admission: every consumer takes the byte-correct drain (the pre-#2156 shape) unless the machine-level RUBASH_PROCSUB_FIFO_MARKER=1 key asserts the installed runtime bridges marker reads — the #1959 streaming route stays armed behind that key (pinned end-to-end: with the key a non-bridging reader sees the marker path while rubash's own bridging cat still streams the bytes through the rendezvous). The identity classification itself is unchanged (path::winuxcmd_fifo_marker_aware and its pins stand). Pins (tests/issue2473_procsub_operand_marker_regressions.rs, #![cfg(windows)]): deterministic end-to-end tests build an aware-class stand-in consumer by hard-linking the rubash binary under a fake WinuxCmd tree (winuxcmd.exe + paste.exe) and invoking it as `paste -c 'cat "$0"'` — one/two/three operands carry their own bytes, the proof key flips the delivery, the key never reaches non-runtime consumers, and the single-operand internal face is unchanged; plus real-WinuxCmd pins (paste 2/3-operand, wc byte count, comm columns, diff actually seeing the difference) that skip when the runtime is absent. Unit pin updated: dispatcher-class consumer drains without the key, marker-routes with it. Verification: WSL GNU Bash 5.3.20 vs the fixed Windows binary, script-file byte-compare — stdout/stderr/rc identical for the issue reproducer plus paste 3-operand, wc count, comm, diff, single-operand cat (artifacts under target/issue-suites/results/issue2473/). cargo test --lib: WSL 1029/0; Windows 1123 passed with 2 failures both identical on pristine origin/master (environment-bound). Neighboring procsub family green except the master-reds already documented in #2472 (issue1959 abandoned-producer et al). Refs #2473 See-also: unixwin/WinuxCmd#1493
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.
What
Fixes #1959 (P2): on Windows, a procsub endpoint delivered as an argv word to an external child was drained to a temp file before spawn — the consumer started only after the producer exited, so external word forms did not stream.
Root cause (file:line)
Every spawn site funnels through
materialize_dev_fd_operands→dev_fd_table_operand(src/executor/dev_fd_operands.rs). The streamed procsub's fd-table endpoint (FdReadEndpoint::File, display path"<(…)", rubash#1952) has no filesystem path, so the Windows face fell intodrain_handle_to_temp— parent reads the producer pipe to EOF into a temp file before spawn. GNU hands the child the live pipe read end under/dev/fd/N(subst.c:6362process_substitute); the unix face already does the equivalent viaunix_fd_attach(live-streamed since #1952).Fix
Deliver the live stream through the #1903 WinuxCmd FIFO-marker rendezvous — the same design piece the issue names:
!<fifo>marker path (create_winux_fifo);file_io.cppm open_fifo_read_handle) and blocks inConnectNamedPipe;open_winux_fifo_write— GNU's blockingO_WRONLYfifo open), copying the procsub read end in byte-wise;DuplicateHandleof the read end, so fd-table cleanup after the child exits cannot race it; closing the writer is the child's EOF; a consumer gone early (GNU's SIGPIPE shape) fails the pump's writes and tears it down; setup failure falls back to the old drain;ReadFileon the same pipe file object (synchronous handles allow one op at a time) — observed blocking the shell for the producer's whole remaining lifetime (10s vs GNU 0s).GNU 5.3.20 A/B (WSL script-file, byte-for-byte)
head -c 7 <(…; sleep 2; touch pd)first\nsearlyfirst\nslatefirst\nsearlysleep 10body)x=$(cat <(…))external catstreamedstarvedstreamedfirst\nlatefirst\nlatePins
mkfifo | tee / headround trip proving the resolved tools are marker/pipe-aware (clean skip where no protocol consumer exists).#[ignore]is lifted — it runs again on non-Windows (unix face unchanged). Windows keeps acfg_attrignore with tool-side reasons only: the suite's airtight PATH resolves an MSYS head that does not speak the marker rendezvous, and WinuxCmd#1442 tracks the head line-mode fifo-operand gap in the toolchain that does (external ledger line, not rubash).Verification
CARGO_TARGET_DIR=… cargo test --release:--lib: 1063 passed / 0 failed--test regression: identical 64-failure set to pristine8755dd7d(environmental — this machine's Git lives outside the harness's minimal-PATH probe; zero deltas),issue1952_pipeline_head_streams_first_line= the one Windows ignore--test cli_tests: identical to pristine exceptversion_appends_build_metadata…, which failed only while the worktree was uncommitted/dirty (green at66393042)