Repository navigation
[probes.command] Fix zombie reaper mechanism - #1130
Merged
Merged
Conversation
This was referenced Aug 19, 2025
manugarg
added a commit
that referenced
this pull request
Sep 2, 2026
Browser probe runs leaked zombie processes: playwright starts browsers detached (setsid), so the browser and the helpers it forks live in a process group of their own. When they're orphaned they get reparented to whoever collects orphans -- cloudprober itself, when it's PID 1 in its container -- and nothing ever waited on them. Waiting on the command's process group, all runcmd_linux.go can do, structurally can't see them. Seen in the field as ~28k <defunct> headless_shell processes after five months, a handful per probe run. We tried reaping generically before (#1130, #1131) and reverted it in #1132: wait4(-1) also reaps our own direct children, stealing exit statuses that probes need, and serializing the reaper against runCommand with an RWMutex just stalls probe execution behind the waiting writer. The missing piece both times was knowing whose zombie it is, which the kernel won't tell us but /proc will: scan for zombie children, and reap only the ones still unclaimed five minutes later. Everything cloudprober starts is waited on immediately -- every spawn site blocks in cmd.Wait/Run/Output before its child can exit -- so a zombie that old has no owner coming for it. Sightings are keyed on (pid, start time), so a recycled pid can't inherit an older process's clock. No wait4(-1), no locks, nothing in the probe path. This runs only when orphans are actually reparented to us, i.e. we're init in our PID namespace or a child subreaper. Otherwise somebody else is already doing the job -- /pause with shareProcessNamespace on Kubernetes, tini with docker's --init -- and Start returns immediately, so those remain good ways to sidestep the mechanism entirely. Also fixes a busy-spin in the existing process-group reaper: it polled wait4 with no delay whenever the group still had live processes, which for the browser probe could mean a 100% CPU spin for minutes. Revisits #1128.
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.
After a lot of research and testing, it's clear to me that my old implementation of zombie reaper doesn't really work. Reason is -- once child process exits, that child's children (cloudprober's grandchildren) will get reparented to
pid 1immediately.Calling
wait4on these grandchildren's pgid (-pgid) is not going to work whether cloudprober ispid 1or not. It should theoretically have worked when cloudprober's pid is 1 because orphaned process will get reparented to cloudprober (e.g. on docker, k8s), but I've confirmed that in practice it doesn't. [Update] I was wrong. In the case I was looking at, descendants were being put in a different process group (pg) by their parents -- that's why waiting on them with their grandparents' pgid didn't work.I've changed my implementation to instead wait on pid
-1, which basically will reap all children of cloudprober. We start one goroutine per cloudprober process that checks every minute for any children to be waited. I've verified that this works in docker environment.This should fix #1128.