Merge pull request #35516 from mlaventure/reduce-race-on-exit

Add missing lock in ProcessEvent
Upstream-commit: 9d00efb533d3561220d169a86ca9ff965f9a6b2c
Component: engine
This commit is contained in:
Sebastiaan van Stijn
2017-11-30 11:30:51 -08:00
committed by GitHub
+4 -2
View File
@@ -50,12 +50,12 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
daemon.LogContainerEvent(c, "oom")
case libcontainerd.EventExit:
if int(ei.Pid) == c.Pid {
c.Lock()
_, _, err := daemon.containerd.DeleteTask(context.Background(), c.ID)
if err != nil {
logrus.WithError(err).Warnf("failed to delete container %s from containerd", c.ID)
}
c.Lock()
c.StreamConfig.Wait()
c.Reset(false)
@@ -72,6 +72,7 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
c.SetStopped(&exitStatus)
defer daemon.autoRemove(c)
}
defer c.Unlock() // needs to be called before autoRemove
// cancel healthcheck here, they will be automatically
// restarted if/when the container is started again
@@ -95,7 +96,9 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
}
}
if err != nil {
c.Lock()
c.SetStopped(&exitStatus)
c.Unlock()
defer daemon.autoRemove(c)
if err != restartmanager.ErrRestartCanceled {
logrus.Errorf("restartmanger wait error: %+v", err)
@@ -105,7 +108,6 @@ func (daemon *Daemon) ProcessEvent(id string, e libcontainerd.EventType, ei libc
}
daemon.setStateCounter(c)
defer c.Unlock()
if err := c.CheckpointTo(daemon.containersReplica); err != nil {
return err
}