X Tutup
Skip to content

fix(agent/reaper): prevent reaper from stealing child exit status#22866

Draft
mafredri wants to merge 1 commit intomainfrom
reaper-fix
Draft

fix(agent/reaper): prevent reaper from stealing child exit status#22866
mafredri wants to merge 1 commit intomainfrom
reaper-fix

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Mar 9, 2026

ForkReap starts a reaper goroutine that calls Wait4(-1, WNOHANG), which
reaps any child. This raced with ForkReap's own Wait4(pid) for the direct
child, causing ECHILD ("no child processes") errors in TestForkReapExitCodes
and TestReapInterrupt.

The fix uses the reapLock parameter that go-reap already supports: we hold
a read lock during our Wait4(pid) so the reaper's write lock blocks until we
have collected the child's status. This keeps the reaper active for zombie
cleanup while the child is running, but prevents it from stealing the direct
child's exit status.

ForkReap starts a reaper goroutine that calls Wait4(-1, WNOHANG),
which reaps any child. This raced with ForkReap's own Wait4(pid)
for the direct child, causing ECHILD errors.

Use the reapLock that go-reap already supports: hold a read lock
during our Wait4(pid) so the reaper's write lock blocks until we
have collected the child's status.
@mafredri mafredri marked this pull request as draft March 9, 2026 22:11
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.

1 participant

X Tutup