Reap orphaned Chrome processes to stop exhausting the PID limit - #13
Merged
Conversation
Chromium leaves helper processes behind on every Playwright run. They get re-parented to PID 1, which was `npm run start` -- npm never calls wait(), so they accumulated as zombies until the container hit its cgroup PID limit and fork() started failing. The symptom was Chromium reporting "Failed to launch zygote process", which Playwright surfaces as "Target page, context or browser has been closed" -- it reads as a test failure, but the tests were fine. A staging pod up for 19 days had 18515 zombies and 37 PIDs left. Two changes: - Add tini as the entrypoint so PID 1 reaps orphans. - The timeout path was orphaning browsers too: exec() spawns `sh -c ...` and childProcess.kill() killed only that shell, cutting npm -> playwright -> chrome loose. Use spawn() with detached: true so the run gets its own process group, and kill the whole tree with process.kill(-pid). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
moufmouf
force-pushed
the
fix/zombie-process-leak
branch
from
July 20, 2026 11:57
086fabb to
3a139ee
Compare
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.
The problem
The staging monitoring pod was reporting test failures that had nothing to do with the test. Playwright was surfacing:
That's Chromium failing to
fork(). The pod had been up 19 days:Chromium leaves helper processes behind on every run. They get re-parented to PID 1, which was
npm run start— npm is not an init and never callswait(), so the orphans stayed as zombies forever, each holding a PID slot.Note that the pod stayed
Running 1/1the entire time. It degraded silently over weeks.The fix
Dockerfile— installtiniand make it the entrypoint, so PID 1 actually reaps orphans.src/index.ts— the timeout path was orphaning browsers at the source.exec("npm run test")spawnssh -c ..., sochildProcess.kill()killed only that shell and cutnpm → playwright → chromeloose. Switched tospawnwithdetached: trueso each run gets its own process group, and the kill now takes the whole tree viaprocess.kill(-pid, 'SIGKILL').Moving from
exectospawnalso means streaming stdout/stderr as they arrive rather than buffering the whole run.Verification
npm run typecheckpasses. Staging was restarted to clear the backlog (zombies can't be reaped without an init — only a restart clears them), and after one run on the current image:2 zombies/run × 288 runs/day at the default 300s interval is how it reached 18,515 in ~19 days. The restart buys a few weeks; this image change is the actual fix.
Not addressed here
helm/values.yamlhasresources: {}, so the pod is unlimited. A memory limit would have turned this into a loud OOMKill weeks earlier instead of a silently degrading pod. Worth a follow-up.🤖 Generated with Claude Code