Skip to content

fix(executor): run deferred output procsub body on input rebind - #3850

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3806-procsub-input-rebind-body
Nov 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3806-procsub-input-rebind-body

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #3806

Summary

  • GNU 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 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 → body abandoned, body2.txt missing.
  • Persistent exec Input/ReadWrite arm now calls flush_persistent_output_process_substitution(fd) before the bind retires the write arm (same flush-before-rebind the output arms already do).
  • SavedNumberedFd now saves/restores fd_output_key + fd_output_process_substitution_key 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 (same union SavedDynamicClose already keeps).

GNU anchors

  • redir.c do_redirection_internal — wholesale dup2 replacement 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 EXISTS identical; written-content (body3=[hello]), compound-scope (body4=[after]), and <> ReadWrite variants all byte-identical.
  • New pin: tests/issue3806_procsub_input_rebind_body.rs (4 tests, cfg(unix)).
  • Fail-first: reproduced on base a41909d in script mode (body2 MISSING).

Generated with Devin

…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>
@caomengxuan666

Copy link
Copy Markdown
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).

@caomengxuan666
caomengxuan666 merged commit 938587b into master Nov 17, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fd: deferred procsub body is dropped after an input rebind (GNU runs it at close)

1 participant