Skip to content

[probes.command] Revert dedicated zombie reaper solutions - #1132

Merged
manugarg merged 1 commit into
mainfrom
external_cleanup_revert
Aug 20, 2025
Merged

manugarg merged 1 commit into
mainfrom
external_cleanup_revert

Conversation

@manugarg

@manugarg manugarg commented Aug 19, 2025 •

Copy link
Copy Markdown
Contributor

This reverts #1130, #1131.

Unfortunately my last attempt at zombie cleanup also doesn't work. This time problem is with the mutex -- when zombieReaper is waiting on the write lock it will block even the read lock acquisition, thus blocking further runCommand executions. I thought of other alternatives but I think trying to manage this out is not worth it.

For the zombie leak problem in docker/k8s environments, where one of the descendants creates another process group thus making those processes out of reach through earlier pgid[1], there is not much we can do in Cloudprober itself. For k8s we'll recommend shareProcessNamespace: true for pod spec and for docker simply --init flag.

[1] - This happens with browser probe where playwright creates some chrome task, which in turn creates some chrome tasks and put them in a different process group.

@manugarg manugarg changed the title [probes.command] Revert dedicated two zombie reaper solutions [probes.command] Revert dedicated zombie reaper solutions Aug 19, 2025
@manugarg
manugarg merged commit f7b2d68 into main Aug 20, 2025
@manugarg
manugarg deleted the external_cleanup_revert branch August 20, 2025 00:57
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.
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