mirror of https://github.com/containers/podman.git
Prevent a potential race when stopping containers
If sending a signal fails, check if the container is alive. If it is not, it probably stopped on its own before we could send the signal, so don't error out. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #591 Approved by: rhatdan
This commit is contained in:
parent
35a10c9ba5
commit
eb0d5dfff1
|
@ -467,6 +467,15 @@ func (r *OCIRuntime) stopContainer(ctr *Container, timeout uint) error {
|
||||||
|
|
||||||
if timeout > 0 {
|
if timeout > 0 {
|
||||||
if err := r.killContainer(ctr, stopSignal); err != nil {
|
if err := r.killContainer(ctr, stopSignal); err != nil {
|
||||||
|
// Is the container gone?
|
||||||
|
// If so, it probably died between the first check and
|
||||||
|
// our sending the signal
|
||||||
|
// The container is stopped, so exit cleanly
|
||||||
|
err := unix.Kill(ctr.state.PID, 0)
|
||||||
|
if err == unix.ESRCH {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,6 +488,12 @@ func (r *OCIRuntime) stopContainer(ctr *Container, timeout uint) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "kill", "--all", ctr.ID(), "KILL"); err != nil {
|
if err := utils.ExecCmdWithStdStreams(os.Stdin, os.Stdout, os.Stderr, r.path, "kill", "--all", ctr.ID(), "KILL"); err != nil {
|
||||||
|
// Again, check if the container is gone. If it is, exit cleanly.
|
||||||
|
err := unix.Kill(ctr.state.PID, 0)
|
||||||
|
if err == unix.ESRCH {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
return errors.Wrapf(err, "error sending SIGKILL to container %s", ctr.ID())
|
return errors.Wrapf(err, "error sending SIGKILL to container %s", ctr.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue