Repository navigation
fix(procsub): run >(body) consumers as detached async children - #1293
Merged
Merged
Conversation
GNU subst.c:6362 process_substitute() forks the write-side `>(...)` consumer with FORK_ASYNC|FORK_PROCSUB: it reads the substitution pipe concurrently and the parent never blocks on it — the child is reaped only by wait/SIGCHLD (jobs.c procsub_add). Rubash ran the body inline at finish_process_substitutions, so `echo hi > >(sleep 1; echo AFTER); echo next` printed AFTER before next and took the full second, and a `while read` consumer double-fed its input through the staged FUNCTION_STDIN mirror (rubash#1221). execute_output_process_substitution now spawns the body as a detached `rubash -c` child whose fd 0 is an OS pipe streaming the temp-carrier bytes from a writer thread — real pacing, and the consumer's output races in late exactly like GNU's forked child. The spawn reuses the `cmd &` respawn transport (function prelude, env whitelist, trap table cancellation, subshell-depth/BASHPID markers, __RUBASH_CMD_FILE fallback) and registers the pid in background_children + $! so `wait $!` and bare `wait` reap it; procsub children stay off `jobs` like GNU's separate procsub list. Verified vs WSL GNU Bash 5.3.20 (script-file probes): echo hello > >(sleep 1; echo AFTER); echo next -> next, ~0.05s echo hello > >(while read -r l; do echo C:$l; done) -> C:hello once echo hi > >(exit 3); echo rc=$? -> rc=0 (child-local) echo hi > >(read l; y=got_$l); echo [$y] -> [] (no leak) Generated with [Devin](https://devin.ai)
caomengxuan666
force-pushed
the
fix/1220-procsub-async-consumer
branch
from
October 23, 2026 07:53
7183072 to
3b005cc
Compare
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.
Fixes #1220
GNU subst.c:6362
process_substitute()forks the write-side>(...)consumer with FORK_ASYNC|FORK_PROCSUB: it reads the substitution pipe concurrently and the parent never blocks on it — the child is reaped only bywait/SIGCHLD (jobs.cprocsub_add). Rubash ran the body inline atfinish_process_substitutions, so a slow consumer stalled the next command.execute_output_process_substitutionnow spawns the body as a detachedrubash -cchild whose fd 0 is an OS pipe streaming the temp-carrier bytes — real pacing, output races in late like GNU's fork. Reuses thecmd &respawn transport (function prelude, env whitelist, trap cancellation, subshell-depth/BASHPID markers,__RUBASH_CMD_FILEfallback) and registers the pid inbackground_children+$!sowait $!/barewaitreap it; stays offjobslike GNU's separate procsub list.Before:
After (== GNU 5.3.20):
Also fixes the consumer-side symptoms noted in the issue:
>(while read...)no longer double-feeds (single real fd-0 channel — the FUNCTION_STDIN duplicate is gone),>(exit 3)is child-local, and body variable assignments no longer leak into the parent.Test plan
cargo test --test issue1220_procsub_write_async— 2 tests green (non-blocking + output still produced)cargo fmt --checkcleanGenerated with Devin