Repository navigation
Don't signal the pid of a command reaped during the wait - #37
Merged
Merged
Conversation
When the wait after the read raises Errno::ECHILD, something else in the process has reaped the command. pid was still set, so the ensure called terminate_and_reap on it. If the pid had already been given to another child of the process, its WNOHANG wait found that child running, and SafeShell sent it TERM, then KILL, and reaped it. Clear pid before re-raising, so the ensure leaves it alone. The same can happen when the call is interrupted after something else has reaped the command, during the read or the grace period: nothing can tell a reaped command from a child that was given its pid. Say so in the README and the docs on execute.
orien
force-pushed
the
echild-no-signal
branch
from
November 29, 2026 15:06
275ef24 to
0490e0a
Compare
orien
marked this pull request as ready for review
November 29, 2026 15:07
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.
Context
When something else in the process reaps the command first, the wait after the read raises
Errno::ECHILD. The command's pid is still set at that point, so the cleanup callsterminate_and_reapon it. If the OS has already given that pid to another child of the process, the cleanup finds that child running and sends it TERM, then KILL, and reaps it.PE-8869
Change
Clears the pid before re-raising the
ECHILD, so the cleanup leaves it alone.The same can happen when the call is interrupted after something else has reaped the command, during the read or during the grace period after TERM. Ruby has no way to tell a reaped command from a child that was given its pid, so the README and the docs on
executenow say a reused pid's new owner can be signalled in that case.Considerations
Process.waitpid: the blocking wait reaps the command and raises, and the cleanup's non-blocking wait reports a running child. It fails onmainwith a TERM sent to that pid.