fix(kbagent): reap zombie processes - #10763
Conversation
|
Auto Cherry-pick Instructions CLA Recheck Instructions |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #10763 +/- ##
==========================================
+ Coverage 64.56% 64.96% +0.39%
==========================================
Files 521 506 -15
Lines 63343 63393 +50
==========================================
+ Hits 40897 41181 +284
+ Misses 18804 18578 -226
+ Partials 3642 3634 -8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
maybe it's simpler to use https://github.com/ramr/go-reaper |
|
Thanks for the suggestion, @cjc7373. We evaluated The in-process Its forked mode avoids that ownership race, but currently does not forward termination signals to the kbagent child and always exits with code 0 instead of propagating the child's exit status. Both behaviors are required for a container PID 1. Making the in-process approach reliable would require replacing kbagent's action execution with a single global process manager that owns every
|
|
Another question. With tini as pid 1, when a kbagent's child process exits and a grandchild process still exists, the grandchild becomes kbagent's direct child (which is tini's grandchild). Now it is not tini's direct child, can tini reap it? |
|
@cjc7373 Yes, tini can reap it. A normal grandparent does not automatically adopt an orphaned grandchild. On Linux, the orphan is reparented to the nearest living child subreaper, or to the PID namespace init process when no such subreaper exists. kbagent is not registered as a child subreaper, while tini is PID 1, so in this case the orphaned grandchild becomes a direct child of tini, not kbagent. When it exits, tini receives SIGCHLD and reaps it with waitpid(-1, ..., WNOHANG). kbagent still owns and waits for its direct action child via cmd.Wait(). tini cannot steal that wait because a process can only wait for its own children; it handles the main kbagent process plus orphaned descendants that have been reparented to it. This is also the behavior described by the Linux child-subreaper semantics and implemented by tini: https://man7.org/linux/man-pages/man2/PR_SET_CHILD_SUBREAPER.2const.html and https://github.com/krallin/tini/blob/master/src/tini.c#L548-L608 |
|
/approve |
What
tini-staticin the tools image and keep it at/bin/tini-statictini-staticbinary when kbagent starts as PID 1Why
kbagent currently runs as PID 1 and does not provide init-process semantics. Orphaned action descendants can therefore remain as zombie processes. Running kbagent under tini ensures orphan adoption and reaping while preserving the existing Pod command and upgrade behavior.
The desired InstanceSet template always contains the new tools image and two-file copy command. Existing custom-image Pods keep their old init image and command as an atomic pair without being restarted; newly created or recreated Pods use the new template and copy both binaries. This compatibility decision is handled by the InstanceSet update path, so explicit restarts, config restarts, application changes, and other recreate-worthy updates retain their normal behavior.
Verification
go test ./cmd/kbagent ./pkg/kbagent/servicego vet ./cmd/kbagent ./pkg/controller/component ./controllers/apps/component ./pkg/controller/instancesetgit diff --checkCloses #10762