From 37edc50c1d91f2e96bc4abae23f2d3da75abbf1a Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Thu, 17 Aug 2017 16:43:41 -0700 Subject: [PATCH] oci: Check if process exists before trying to kill it Signed-off-by: Mrunal Patel --- oci/oci.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/oci/oci.go b/oci/oci.go index 2eb14f0c..3243e593 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -496,8 +496,16 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp func (r *Runtime) StopContainer(c *Container, timeout int64) error { c.opLock.Lock() defer c.opLock.Unlock() + + // Check if the process is around before sending a signal + err := unix.Kill(c.state.Pid, 0) + if err == unix.ESRCH { + c.state.Finished = time.Now() + return nil + } + if err := utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.Path(c), "kill", c.id, c.GetStopSignal()); err != nil { - return err + return fmt.Errorf("failed to stop container %s, %v", c.id, err) } if timeout == -1 { // default 10 seconds delay