Merge pull request #41698 from cpuguy83/fix_shutdown_handling

Move container exit state to after cleanup.
This commit is contained in:
Sebastiaan van Stijn 2021-02-11 20:18:00 +01:00 committed by GitHub
commit 264353425a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -53,6 +53,15 @@ func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontaine
}
restart, wait, err := c.RestartManager().ShouldRestart(ec, daemon.IsShuttingDown() || c.HasBeenManuallyStopped, time.Since(c.StartedAt))
// cancel healthcheck here, they will be automatically
// restarted if/when the container is started again
daemon.stopHealthchecks(c)
attributes := map[string]string{
"exitCode": strconv.Itoa(int(ec)),
}
daemon.Cleanup(c)
if err == nil && restart {
c.RestartCount++
c.SetRestarting(&exitStatus)
@ -62,17 +71,11 @@ func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontaine
}
defer c.Unlock() // needs to be called before autoRemove
// cancel healthcheck here, they will be automatically
// restarted if/when the container is started again
daemon.stopHealthchecks(c)
attributes := map[string]string{
"exitCode": strconv.Itoa(int(ec)),
}
daemon.LogContainerEventWithAttributes(c, "die", attributes)
daemon.Cleanup(c)
daemon.setStateCounter(c)
cpErr := c.CheckpointTo(daemon.containersReplica)
daemon.LogContainerEventWithAttributes(c, "die", attributes)
if err == nil && restart {
go func() {
err := <-wait