Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

kill_zombie_parents.sh kills tenant workloads: it SIGTERM/SIGKILLs a container's PID 1 #657

Open

Description

@cmartins88

Summary

kill_zombie_parents.sh — shipped in provider-playbooks/roles/os/files/ and recommended by the Kubespray provider docs as "Step 11 — Install zombie process killer (recommended)" — escalates SIGCHLD → SIGTERM → SIGKILL against the parent of a zombie process whenever the parent chain tops out at containerd-shim.

On a Kubernetes node that parent is normally PID 1 inside a container, so the escalation kills the tenant's workload.

Any provider that followed the documented setup is silently killing tenant deployments on a 5-minute cadence.

Why it is very hard to attribute

The signal originates on the host, so kubelet never makes a decision:

  • no Killing, Evicted, Preempted or OOMKilling event
  • the pod is not replaced — the pod name stays stable, the container restarts in place, restartCount climbs
  • to the tenant it looks like an unexplained CrashLoopBackOff with no cause in kubectl describe

The only trace is the node journal under tag kill_zombie_parents.

The give-away is timing: container deaths land on a 5-minute wall-clock cadence that is independent of container start time, so lifetimes look random. In the report that led us here, the container lived 73s, 311s, 290s, 272s and 256s, while the deaths fell at 11:45:20, 11:50:32, 11:55:34, 12:00:34, 12:05:32.

Evidence

A tenant reported a GPU workload being killed by an external SIGTERM every few minutes. Their supervisor logs signal receipt, and the node journal lines up exactly:

11:45:02 Found zombie process 407933 with immediate parent 407847
11:45:02 Parent chain: 407756:(containerd-shim) 407847:(cloud-game-supe)
11:45:02 Top-level parent is containerd-shim
11:45:02 Attempting to send SIGCHLD to parent process 407847
11:45:18 Zombie process 407933 still exists after SIGCHLD
11:45:18 Attempting to send SIGTERM to parent process 407847   <-- kills the container

407847 is a direct child of the shim — i.e. PID 1 inside the container.

Measured across our three production clusters (23 nodes, 30 days):

Cluster nodes SIGTERM SIGKILL
A 10 261 99
B 6 2953 2050
C 7 407 397
total 23 3621 2546

Parent-chain depth 2 (shim → init) accounts for 256 of 261 on cluster A and the overwhelming majority elsewhere — so almost every one of those signals hit a container's PID 1. Two nodes were killing a workload roughly 40 times a day, for a month.

Root cause

immediate_parent=$(echo "$parent_chain" | awk -F' ' '{print $1}' | cut -d':' -f1)
if [[ $immediate_parent != $parent_pid ]]; then
  if attempt_kill $parent_pid -SIGCHLD 15 "SIGCHLD"; then
  elif attempt_kill $parent_pid -SIGTERM 15 "SIGTERM"; then
  elif attempt_kill $parent_pid -SIGKILL 5 "SIGKILL"; then

awk '{print $1}' returns the first element of the chain, which get_parent_chain builds outermost-first — so immediate_parent actually holds the top of the chain (the shim), despite its name. The condition therefore reads "the zombie's parent is not the shim itself", which is true for essentially every containerised process. The script then signals that parent, with no check for whether it is init in its own PID namespace.

Two secondary issues:

  • find_zombie_and_parents returns after the first zombie found, so the script cannot clear a backlog. One of our nodes was sitting at 24 zombies while running it.
  • A zombie child of a container's init is harmless — it costs one PID slot and is released when the container exits. Our nodes that never had the script show 0–65 transient zombies against pid_max 4194304.

Suggested fix

Never signal a process that is init in its own PID namespace, and never escalate past SIGCHLD for anything inside a namespace. /proc/<pid>/status NSpid: gives both facts:

# entries in NSpid == namespace depth; 1 means host namespace (not a container)
nspid_depth() { awk '/^NSpid:/{print NF-1}' "/proc/$1/status" 2>/dev/null; }
# last entry == the pid as seen inside its innermost namespace; 1 means init
nspid_inner() { awk '/^NSpid:/{print $NF}'  "/proc/$1/status" 2>/dev/null; }

# refuse if nspid_inner == 1            -> container init, killing it kills the workload
# refuse any non-SIGCHLD if depth > 1   -> process lives inside a container

SIGCHLD is safe to keep unconditionally: its default disposition is ignore, so it cannot harm a healthy process, and it is the entire legitimate mechanism here. If SIGCHLD does not clear the zombie, the zombie is harmless anyway.

The correct control for PID exhaustion — the risk this script is aiming at — is kubelet's podPidsLimit, not signalling tenant init processes.

Results after applying the fix

We have been running a hardened version with these guards on all 23 nodes for 20.8 hours:

  • 813 cron runs found zombies; 860 SIGCHLD nudges sent
  • 0 SIGTERM, 0 SIGKILL, 0 script errors
  • at the previous 30-day rate the old script would have sent roughly 104 SIGTERM + 73 SIGKILL in the same window
  • live zombie counts are now 0 on 20 of 23 nodes (max 5) — no accumulation, which is the outcome the escalation was supposed to prevent

So dropping the escalation costs nothing and stops the tenant kills outright.

Happy to open a PR against provider-playbooks with the guarded version if that is useful.

Activity

  1. cmartins88 commented on Sep 8, 2026

    @cmartins88
    Author

    One addition, so whoever picks this up fixes it in both places.

    The affected script has two independent distribution paths, and the issue above only names one of them:

    1. provider-playbooks/roles/os/files/kill_zombie_parents.sh — still shipping the affected version as of today.
    2. The Kubespray provider docs inline the entire script in the page itself, under STEP 11 - Install Zombie Process Killer (Recommended). It is not fetched from the playbooks repo — the operator copy-pastes it from a heredoc in the docs.

    The inlined copy carries the same logic, including the line that causes the problem:

    immediate_parent=$(echo "$parent_chain" | awk -F' ' '{print $1}' | cut -d':' -f1)
    ...
    if   attempt_kill $parent_pid -SIGCHLD 15 "SIGCHLD"; then
    elif attempt_kill $parent_pid -SIGTERM 15 "SIGTERM"; then
    elif attempt_kill $parent_pid -SIGKILL  5 "SIGKILL"; then

    get_parent_chain builds the chain outermost-first, so awk '{print $1}' returns the top of the chain (the containerd-shim), not the immediate parent as the variable name suggests. The condition [[ $immediate_parent != $parent_pid ]] therefore reads "the zombie's parent is not the shim itself", which is true for essentially every containerised process — and the escalation then signals that parent, which is normally PID 1 inside the container.

    This means the affected population is wider than just provider-playbooks users: anyone who followed the Kubespray guide by hand has it too, and patching only the ansible role would leave the docs still handing it out.

    For anyone wanting to check their own nodes (read-only):

    journalctl -t kill_zombie_parents --since "30 days ago" | grep -c "Attempting to send SIGTERM"

    Anything above 0 is a process inside a container that was signalled — the script only reaches that branch when the parent chain tops out at a containerd-shim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions