فهرست منبع

Fix a potential hang when starting after a non-clean shutdown

Previous startup sequence used to call "containerStop" on containers that were persisted with a running state but are not alive when restarting (can happen on non-clean shutdown).
This call was made before fixing-up the RunningState of the container, and tricked the daemon to trying to kill a non-existing process and ultimately hang.

The fix is very simple - just add a condition on calling containerStop.

Signed-off-by: Simon Ferquel <simon.ferquel@docker.com>
Simon Ferquel 4 سال پیش
والد
کامیت
af0665861b
1فایلهای تغییر یافته به همراه3 افزوده شده و 1 حذف شده
  1. 3 1
      daemon/daemon.go

+ 3 - 1
daemon/daemon.go

@@ -348,13 +348,14 @@ func (daemon *Daemon) restore() error {
 				log.WithError(err).Error("failed to restore container with containerd")
 				log.WithError(err).Error("failed to restore container with containerd")
 				return
 				return
 			}
 			}
+			log.Debugf("alive: %v", alive)
 			if !alive && process != nil {
 			if !alive && process != nil {
 				ec, exitedAt, err = process.Delete(context.Background())
 				ec, exitedAt, err = process.Delete(context.Background())
 				if err != nil && !errdefs.IsNotFound(err) {
 				if err != nil && !errdefs.IsNotFound(err) {
 					log.WithError(err).Error("failed to delete container from containerd")
 					log.WithError(err).Error("failed to delete container from containerd")
 					return
 					return
 				}
 				}
-			} else if !daemon.configStore.LiveRestoreEnabled {
+			} else if alive && !daemon.configStore.LiveRestoreEnabled {
 				if err := daemon.shutdownContainer(c); err != nil && !errdefs.IsNotFound(err) {
 				if err := daemon.shutdownContainer(c); err != nil && !errdefs.IsNotFound(err) {
 					log.WithError(err).Error("error shutting down container")
 					log.WithError(err).Error("error shutting down container")
 					return
 					return
@@ -393,6 +394,7 @@ func (daemon *Daemon) restore() error {
 
 
 				if !alive {
 				if !alive {
 					c.Lock()
 					c.Lock()
+					log.Debug("setting stopped state")
 					c.SetStopped(&container.ExitStatus{ExitCode: int(ec), ExitedAt: exitedAt})
 					c.SetStopped(&container.ExitStatus{ExitCode: int(ec), ExitedAt: exitedAt})
 					daemon.Cleanup(c)
 					daemon.Cleanup(c)
 					if err := c.CheckpointTo(daemon.containersReplica); err != nil {
 					if err := c.CheckpointTo(daemon.containersReplica); err != nil {