Repository navigation
Ensure that grandchildren cannot keep an exited child alive. - #152
Merged
ltratt merged 1 commit intoSep 24, 2026
Merged
Conversation
snare previously only checked for a child's exit when its stderr and stdout were closed. This works fine except when the child has handed stderr's and/or stdout's file handles to grandchildren which have (for whatever reason) not exited. The fix is conceptually simple but has annoying details: we already use SIGCHLD to inform us when a (we don't know which!) child process has died. So we now use `try_wait` to see if a child has exited without worrying about whether stderr/stdout have `HUP`ed. That then means that there may be data in both file handles that we haven't read, which we need to deal with. But in the "grandchildren are alive" situation, reading from them may never reach EOF, so we only read the data that's available: fortunately, for the "normal" situation this does the right thing. While testing this I ran into a bug in rust + OpenBSD which it turns out is fixed in rust-nightly but not in 1.98.1, so I went down that rathole, and the fix for that ends up in here. Oh well.
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.
snare previously only checked for a child's exit when its stderr and stdout were closed. This works fine except when the child has handed stderr's and/or stdout's file handles to grandchildren which have (for whatever reason) not exited.
The fix is conceptually simple but has annoying details: we already use SIGCHLD to inform us when a (we don't know which!) child process has died. So we now use
try_waitto see if a child has exited without worrying about whether stderr/stdout haveHUPed. That then means that there may be data in both file handles that we haven't read, which we need to deal with. But in the "grandchildren are alive" situation, reading from them may never reach EOF, so we only read the data that's available: fortunately, for the "normal" situation this does the right thing.While testing this I ran into a bug in rust + OpenBSD which it turns out is fixed in rust-nightly but not in 1.98.1, so I went down that rathole, and the fix for that ends up in here. Oh well.