Skip to content

Commit 37edc50

Browse files
committed
oci: Check if process exists before trying to kill it
Signed-off-by: Mrunal Patel <[email protected]>
1 parent 908b3fc commit 37edc50

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

oci/oci.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,16 @@ func (r *Runtime) ExecSync(c *Container, command []string, timeout int64) (resp
496496
func (r *Runtime) StopContainer(c *Container, timeout int64) error {
497497
c.opLock.Lock()
498498
defer c.opLock.Unlock()
499+
500+
// Check if the process is around before sending a signal
501+
err := unix.Kill(c.state.Pid, 0)
502+
if err == unix.ESRCH {
503+
c.state.Finished = time.Now()
504+
return nil
505+
}
506+
499507
if err := utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.Path(c), "kill", c.id, c.GetStopSignal()); err != nil {
500-
return err
508+
return fmt.Errorf("failed to stop container %s, %v", c.id, err)
501509
}
502510
if timeout == -1 {
503511
// default 10 seconds delay

0 commit comments

Comments
 (0)