From 356ca75757646ecddefee266aa749cda12cdedbe Mon Sep 17 00:00:00 2001 From: Jeff Zvier Date: Tue, 18 Jan 2022 19:57:34 +0800 Subject: [PATCH] containerd-shim-runc-v2: return init pid when clean dead shim If containerd-shim-runc-v2 process dead abnormally, such as received kill 9 signal, panic or other unkown reasons, the containerd-shim-runc-v2 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. Signed-off-by: Jeff Zvier --- runtime/v2/runc/manager/manager_linux.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/v2/runc/manager/manager_linux.go b/runtime/v2/runc/manager/manager_linux.go index 39e97e9f6..0f5014677 100644 --- a/runtime/v2/runc/manager/manager_linux.go +++ b/runtime/v2/runc/manager/manager_linux.go @@ -270,8 +270,13 @@ func (manager) Stop(ctx context.Context, id string) (shim.StopStatus, error) { if err := mount.UnmountAll(filepath.Join(path, "rootfs"), 0); err != nil { log.G(ctx).WithError(err).Warn("failed to cleanup rootfs mount") } + pid, err := runcC.ReadPidFile(filepath.Join(path, process.InitPidFile)) + if err != nil { + log.G(ctx).WithError(err).Warn("failed to read init pid file") + } return shim.StopStatus{ ExitedAt: time.Now(), ExitStatus: 128 + int(unix.SIGKILL), + Pid: pid, }, nil }