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:
commit
f5d3311839
1 changed files with 17 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue