CRI: stop signal dropped when StopContainer follows StartContainer, container runs until timeout

Aperta
#14,672 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Dineshjnld ci sta già lavorando.

Dal 29/11/2026.

  • #14674 di @Dineshjnld — aperta
  • #14677 di @Jeremiah-D — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, linux, python

Direzione di ricerca

Start with internal/cri/server/container_stop.go and the linked Linux kernel/signal.c behavior, then inspect libcontainer/standard_init_linux.go to understand the start/exec race. Reproduce with the provided crictl commands and the Python PID-namespace container, observing /proc/<pid>/status for SigCgt and SigBlk. The fix is complete when StopContainer retries the stop signal during its timeout while init neither catches nor blocks it, and the reproducer exits promptly instead of waiting for SIGKILL.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

If StopContainer arrives right after StartContainer returns, the stop signal can reach the container's PID 1 before the process has installed its handler. The kernel discards a default-action signal sent to a PID namespace init (signal.c), and containerd sends the stop signal only once (container_stop.go), so the container keeps running until the SIGKILL at the end of the timeout.

runc start returns before init execs the user process (standard_init_linux.go), and after exec the program still has to get to its handler setup. The kubelet lands in this window whenever a pod is deleted while it is starting (e.g. during the image pull): it calls StopContainer ~1.5 ms after StartContainer returns and then waits the full terminationGracePeriodSeconds. We noticed it when a CloudNativePG pod deleted during startup ignored SIGTERM and held up a node drain for its 1800s grace period.

Steps to reproduce the issue

Python whose first statement installs a SIGTERM handler. "pid":1 gives the container its own PID namespace, as the kubelet does. Drop cgroup_parent if containerd uses cgroupfs.

cat > pod.json <<'J'
{"metadata":{"name":"sigtest","namespace":"default","uid":"sigtest"},"linux":{"cgroup_parent":"system.slice"}}
J
cat > ctr.json <<'J'
{"metadata":{"name":"app"},"image":{"image":"docker.io/library/python:3.14-slim"},
 "command":["python3","-c","import signal,sys,time\nsignal.signal(signal.SIGTERM, lambda *a: sys.exit(0))\ntime.sleep(3600)"],
 "linux":{"security_context":{"namespace_options":{"pid":1}}}}
J
crictl pull docker.io/library/python:3.14-slim >/dev/null
POD=$(crictl runp pod.json); CTR=$(crictl create $POD ctr.json pod.json)
crictl start $CTR; time crictl stop -t 30 $CTR
crictl inspect -o go-template --template '{{.status.exitCode}}' $CTR
Describe the results you received and expected

crictl stop -t 30 takes 30s and the exit code is 137, in 20 of 20 runs. The signal/signal_generate tracepoint shows the SIGTERM hitting python3 (already exec'd) with res=1 (ignored). With sleep 1 between start and stop, or with a second SIGTERM sent from the host, it exits 0 right away. Through the kubelet (v1.37.0 in kind), deleting the pod during its image pull takes the full grace period.

Expected: the container gets the stop signal and exits within milliseconds.

What version of containerd are you using?

containerd v2.3.7 (also v2.3.4 and main at 0e1fb1bf)

Any other relevant information

runc 1.4.3, kernel 7.2.12 arm64, Debian 13 (kind node). Not specific to Python: a static Go binary whose main starts with signal.Notify lost it in 5 of 30 runs under a 100m CPU limit, with StopContainer sent right after StartContainer.

Suggested fix: keep re-sending the stop signal during the timeout while the init process neither catches nor blocks it (SigCgt/SigBlk in /proc/<pid>/status), instead of sending it exactly once.

Lingua principale
Go
Stelle
21.6k
Fork
4.2k
Merge medio
2g 9h
PR unite (30g)
86

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di containerd/containerd

Tutte le issue di containerd/containerd

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.