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

オープン
#14,672 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Dineshjnld がすでに取り組んでいます。

2026年11月29日 から。

  • #14674 @Dineshjnld による — オープン
  • #14677 @Jeremiah-D による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, linux, python

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
21.6k
フォーク
4.2k
平均マージ
2日 9時間
マージ済み PR(30日)
86

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

containerd/containerd のほかの issue

containerd/containerd の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。