From 7901f4b33189772eadbf2fb3cde646fda75c1458 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Sun, 20 Feb 2022 15:08:23 +0800 Subject: [PATCH] containerd-shim-runc-v1: return init pid when clean dead shim If containerd-shim-runc-v1 process dead abnormally, such as received kill -s 9 signal, panic or other unkown reasons, the containerd-shim-runc-v1 server can not reap runc container and forward init process exit event. This will lead the container leaked in dockerd. When shim dead, containerd will clean dead shim, here read init process pid and forward exit event with pid at the same time. Related to: #6402 Signed-off-by: Jeff Zvier Signed-off-by: Wei Fu --- runtime/v2/runc/v1/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/runtime/v2/runc/v1/service.go b/runtime/v2/runc/v1/service.go index b630711db9f6..0c84c1403929 100644 --- a/runtime/v2/runc/v1/service.go +++ b/runtime/v2/runc/v1/service.go @@ -259,9 +259,16 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error) if err := mount.UnmountAll(filepath.Join(path, "rootfs"), 0); err != nil { logrus.WithError(err).Warn("failed to cleanup rootfs mount") } + + pid, err := runcC.ReadPidFile(filepath.Join(path, process.InitPidFile)) + if err != nil { + logrus.WithError(err).Warn("failed to read init pid file") + } + return &taskAPI.DeleteResponse{ ExitedAt: time.Now(), ExitStatus: 128 + uint32(unix.SIGKILL), + Pid: uint32(pid), }, nil }