Переглянути джерело

daemon: Daemon.handleContainerExit(): reduce ambiguity in error handling

This goroutine was added in c458bca6dc25c25d3345b093592167f2bd5e4af9, and
looks for errors from the wait channel. If no error is returned, it attempts
to start the container, and *updates* the error if a failure happened while
doing so, so that the code below it can update the container's status, and
perform auto-remove (if set for the container).

However, due to the formatting of the code, it was easy to overlook that
the "err" variable was not local to the "if" statement.

This patch breaks up the if-statement in an attempt to make it clearer that
this is not a local "err" variable, and adds a code-comment explaining the
logic.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 рік тому
батько
коміт
f8363690ca
1 змінених файлів з 5 додано та 1 видалено
  1. 5 1
      daemon/monitor.go

+ 5 - 1
daemon/monitor.go

@@ -121,7 +121,11 @@ func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontaine
 				// So to avoid panic at startup process, here must wait util daemon restore done.
 				daemon.waitForStartupDone()
 				cfg := daemon.config() // Apply the most up-to-date daemon config to the restarted container.
-				if err = daemon.containerStart(context.Background(), cfg, c, "", "", false); err != nil {
+
+				// update the error if we fail to start the container, so that the cleanup code
+				// below can handle updating the container's status, and auto-remove (if set).
+				err = daemon.containerStart(context.Background(), cfg, c, "", "", false)
+				if err != nil {
 					log.G(ctx).Debugf("failed to restart container: %+v", err)
 				}
 			}