Skip to content

[probes.command] Don't run zombie reaper while direct children are running - #1131

Merged
manugarg merged 1 commit into
mainfrom
external_cleanup_3
Aug 19, 2025
Merged

manugarg merged 1 commit into
mainfrom
external_cleanup_3

Conversation

@manugarg

Copy link
Copy Markdown
Contributor
  • This is a follow up to [probes.command] Fix zombie reaper mechanism #1130. That was not sufficient as zombiereaper goroutine could reap the direct children before we could collect their status.
  • Use mutexes to make sure zombiereaper is not run while we are running the direct child.

@manugarg
manugarg merged commit 9126dc2 into main Aug 19, 2025
@manugarg
manugarg deleted the external_cleanup_3 branch August 19, 2025 18:44
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