From 92ebe61fea0d1035914538e24add0cada0fe5c32 Mon Sep 17 00:00:00 2001 From: Alexandru Matei Date: Mon, 21 Nov 2022 11:53:27 +0200 Subject: [PATCH] runtime: reap force killed processes reap child processes after sending SIGKILL Fixes #5739 Signed-off-by: Alexandru Matei --- src/runtime/virtcontainers/utils/utils.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/runtime/virtcontainers/utils/utils.go b/src/runtime/virtcontainers/utils/utils.go index 8b05bfc2f..6197f39b7 100644 --- a/src/runtime/virtcontainers/utils/utils.go +++ b/src/runtime/virtcontainers/utils/utils.go @@ -375,8 +375,19 @@ outer: if pidRunning { // Force process to die if err = syscall.Kill(pid, syscall.SIGKILL); err != nil { + if err == syscall.ESRCH { + logger.WithField("pid", pid).Warnf("process already finished") + return nil + } return fmt.Errorf("Failed to stop process %v: %s", pid, err) } + + for { + _, err := syscall.Wait4(pid, nil, 0, nil) + if err != syscall.EINTR { + break + } + } } return nil