1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #13449 from duglin/FixRaceInStop

Fix race condition on container stop
This commit is contained in:
David Calavera 2015-05-27 13:05:53 -07:00
commit f5d3311839

View file

@ -437,7 +437,23 @@ func (container *Container) Kill() error {
// 1. Send SIGKILL
if err := container.killPossiblyDeadProcess(9); err != nil {
return err
// While normally we might "return err" here we're not going to
// because if we can't stop the container by this point then
// its probably because its already stopped. Meaning, between
// the time of the IsRunning() call above and now it stopped.
// Also, since the err return will be exec driver specific we can't
// look for any particular (common) error that would indicate
// that the process is already dead vs something else going wrong.
// So, instead we'll give it up to 2 more seconds to complete and if
// by that time the container is still running, then the error
// we got is probably valid and so we return it to the caller.
if container.IsRunning() {
container.WaitStop(2 * time.Second)
if container.IsRunning() {
return err
}
}
}
// 2. Wait for the process to die, in last resort, try to kill the process directly