Skip to content

Commit 6f45108

Browse files
committed
runc.v1/v2: return init pid when clean dead shim
If containerd-shim-runc-v1/v2 process dead abnormally, such as received kill 9 signal, panic or other unkown reasons, the containerd-shim-runc-v1/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 <[email protected]> Signed-off-by: Wei Fu <[email protected]>
1 parent 6ddbd47 commit 6f45108

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

runtime/v2/runc/v1/service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build linux
12
// +build linux
23

34
/*
@@ -247,9 +248,16 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error)
247248
if err := mount.UnmountAll(filepath.Join(path, "rootfs"), 0); err != nil {
248249
logrus.WithError(err).Warn("failed to cleanup rootfs mount")
249250
}
251+
252+
pid, err := runcC.ReadPidFile(filepath.Join(path, process.InitPidFile))
253+
if err != nil {
254+
logrus.WithError(err).Warn("failed to read init pid file")
255+
}
256+
250257
return &taskAPI.DeleteResponse{
251258
ExitedAt: time.Now(),
252259
ExitStatus: 128 + uint32(unix.SIGKILL),
260+
Pid: uint32(pid),
253261
}, nil
254262
}
255263

runtime/v2/runc/v2/service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build linux
12
// +build linux
23

34
/*
@@ -321,9 +322,16 @@ func (s *service) Cleanup(ctx context.Context) (*taskAPI.DeleteResponse, error)
321322
if err := mount.UnmountAll(filepath.Join(path, "rootfs"), 0); err != nil {
322323
logrus.WithError(err).Warn("failed to cleanup rootfs mount")
323324
}
325+
326+
pid, err := runcC.ReadPidFile(filepath.Join(path, process.InitPidFile))
327+
if err != nil {
328+
logrus.WithError(err).Warn("failed to read init pid file")
329+
}
330+
324331
return &taskAPI.DeleteResponse{
325332
ExitedAt: time.Now(),
326333
ExitStatus: 128 + uint32(unix.SIGKILL),
334+
Pid: uint32(pid),
327335
}, nil
328336
}
329337

0 commit comments

Comments
 (0)