Repository navigation
fix(executor): run deferred output procsub body on input rebind - #3850
Merged
Merged
Conversation
…3806) GNU's redir.c do_redirection_internal applies every redirect with dup2 onto the redirector, so `exec 2<input.txt` after `exec 2> >(cat > f)` closes the old write descriptor — the substitution reader sees EOF and the forked body finishes, creating f. Rubash defers the body and registers it in the fd's output ledger; the input bind's clear_output_fd_mirrors removed that registration before the final close could run it, so the body was abandoned. Two halves of the same lifetime invariant: the persistent exec Input/ReadWrite arm now flushes the substitution before the bind retires the write arm (mirroring the output arm's existing flush-before-rebind), and SavedNumberedFd saves/restores the output ledger keys with the rest of the slot state so a compound scope's input bind cannot strand a restored procsub endpoint whose body can never run — the same union SavedDynamicClose already keeps. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Member
Author
|
g3 lane: WSL Linux-native verified. Pin stem issue3806_procsub_input_rebind_body 4/4 pass; GNU 5.3.20 script-file comparison byte-identical (exec rebind, written content, compound scope, <> ReadWrite); -D warnings clean; rustfmt applied. Fail-first reproduced on base a41909d (script mode: body2 MISSING). |
This was referenced Nov 17, 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.
Fixes #3806
Summary
redir.c do_redirection_internalapplies every redirect withdup2onto the redirector, soexec 2<input.txtafterexec 2> >(cat > f)closes the old write descriptor — the substitution reader sees EOF and the body finishes, creatingf.clear_output_fd_mirrorsremoved that registration before the final close could run it → body abandoned,body2.txtmissing.Input/ReadWritearm now callsflush_persistent_output_process_substitution(fd)before the bind retires the write arm (same flush-before-rebind the output arms already do).SavedNumberedFdnow saves/restoresfd_output_key+fd_output_process_substitution_keywith the rest of the slot state, so a compound scope's input bind cannot strand a restored procsub endpoint whose body can never run (same unionSavedDynamicClosealready keeps).GNU anchors
redir.c do_redirection_internal— wholesaledup2replacement of the redirector.subst.c process_substitute— body runs when the last write descriptor closes.Verification (WSL, GNU bash 5.3.20 script-file oracle)
exec 2> >(cat > body2.txt); exec 2<input.txt; exec 2>&-→body2 EXISTSidentical; written-content (body3=[hello]), compound-scope (body4=[after]), and<>ReadWrite variants all byte-identical.tests/issue3806_procsub_input_rebind_body.rs(4 tests, cfg(unix)).body2 MISSING).Generated with Devin