diff --git a/libcontainer/container_linux.go b/libcontainer/container_linux.go index 8abdc3fe9..3dca29e4c 100644 --- a/libcontainer/container_linux.go +++ b/libcontainer/container_linux.go @@ -2067,9 +2067,20 @@ func ignoreTerminateErrors(err error) error { if err == nil { return nil } + // terminate() might return an error from ether Kill or Wait. + // The (*Cmd).Wait documentation says: "If the command fails to run + // or doesn't complete successfully, the error is of type *ExitError". + // Filter out such errors (like "exit status 1" or "signal: killed"). + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { + return nil + } + // TODO: use errors.Is(err, os.ErrProcessDone) here and + // remove "process already finished" string comparison below + // once go 1.16 is minimally supported version. + s := err.Error() - if strings.Contains(s, "signal: killed") || - strings.Contains(s, "process already finished") || + if strings.Contains(s, "process already finished") || strings.Contains(s, "Wait was already called") { return nil }