Ver código fonte

Merge pull request #13449 from duglin/FixRaceInStop

Fix race condition on container stop
David Calavera 10 anos atrás
pai
commit
f5d3311839
1 arquivos alterados com 17 adições e 1 exclusões
  1. 17 1
      daemon/container.go

+ 17 - 1
daemon/container.go

@@ -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