Repository navigation
fix(coproc): dead coprocs unbind NAME/NAME_PID at the command boundary - #1198
Merged
Merged
Conversation
…y (rubash#1023)
The per-command background-refresh spared finished coprocs whose name
the upcoming command's redirects referenced (coprocs_referenced_by_command /
protected_coprocs), so two simultaneous named coprocs kept both arrays
forever. GNU has no such protection: cleanup_dead_jobs -> coproc_reap
(jobs.c:1342, reached from notify_and_cleanup at each input line and
from stop_pipeline after every spawned pipeline) disposes each
COPROC_DEAD entry via coproc_dispose -> coproc_unsetvars
(execute_cmd.c:2166, :2450), unbinding <name> and <name>_PID, so
`cat <&${A[0]}` on a reaped coproc reports `ambiguous redirect`.
GNU anchors:
- jobs.c:1342 cleanup_dead_jobs -> coproc_reap -> cpl_reap
- execute_cmd.c:2166 coproc_dispose -> :2450 coproc_unsetvars
- execute_cmd.c:2579 execute_coproc -> stop_pipeline -> cleanup_dead_jobs
Verified against WSL GNU bash 5.3.20: two exited coprocs + sleep +
`cat <&${A[0]}` on each prints `ambiguous redirect` for both, rc=1 —
byte-identical after this change. Live coprocs (coproc.tests shape:
read/write while the child runs) are untouched — only COPROC_DEAD
entries are ever disposed.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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 #1023
Summary
GNU bash tears a dead coproc down at the first reap point after its exit:
cleanup_dead_jobs -> coproc_reap(jobs.c:1342) disposes everyCOPROC_DEADentry viacoproc_dispose -> coproc_unsetvars(execute_cmd.c:2166, :2450), unbinding<name>and<name>_PID. rubash's per-command refresh skipped exactly the coprocs the next command's redirects referenced (protected_coprocs), so the issue's two simultaneous named coprocs kept both var sets alive.The carve-out is removed: a finished coproc is disposed at the command boundary regardless of what the next command references — matching GNU, which consults nothing about upcoming words. Live coprocs are unaffected (only observed-dead children are retired), so
coproc.tests-shaped read/write roundtrips still work.Before / after (vs WSL GNU bash 5.3.20)
GNU:
rubash before:
one,two,done rc=0— both var sets kept.rubash after: byte-identical to GNU.
Without the
sleepthe outcome is timing-dependent in GNU itself (the issue notes "GNU's victim varies run to run"); the mechanism — not the race winner — is what now matches.Test plan
tests/issue1023_coproc_unbind.rs: two dead coprocs → both ambiguous; dead coproc referenced by next redirect → unbound; live coproc → vars bound + echo roundtrip workscargo test --test regression— 78/78 greencargo fmt --checkcleanGenerated with Devin