From c18848f023a4b004a9185ec5550ccc719b85bd47 Mon Sep 17 00:00:00 2001 From: Gabriel Monroy Date: Fri, 2 May 2014 13:27:17 -0600 Subject: [PATCH] deregister containers before removing driver and containerGraph references This is required to address a race condition described in #5553, where a container can be partially deleted -- for example, the root filesystem but not the init filesystem -- which makes it impossible to delete the container without re-adding the missing filesystems manually. This behavior has been witnessed when rebooting boxes that are configured to remove containers on shutdown in parallel with stopping the Docker daemon. Docker-DCO-1.1-Signed-off-by: Gabriel Monroy (github: gabrtv) Upstream-commit: 9f152aacf8427cbd20a70d52d633f8a6d624aff5 Component: engine --- components/engine/daemon/daemon.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/engine/daemon/daemon.go b/components/engine/daemon/daemon.go index 64a53989d0..22182f389f 100644 --- a/components/engine/daemon/daemon.go +++ b/components/engine/daemon/daemon.go @@ -272,6 +272,10 @@ func (daemon *Daemon) Destroy(container *Container) error { return err } + // Deregister the container before removing its directory, to avoid race conditions + daemon.idIndex.Delete(container.ID) + daemon.containers.Remove(element) + if err := daemon.driver.Remove(container.ID); err != nil { return fmt.Errorf("Driver %s failed to remove root filesystem %s: %s", daemon.driver, container.ID, err) } @@ -285,9 +289,6 @@ func (daemon *Daemon) Destroy(container *Container) error { utils.Debugf("Unable to remove container from link graph: %s", err) } - // Deregister the container before removing its directory, to avoid race conditions - daemon.idIndex.Delete(container.ID) - daemon.containers.Remove(element) if err := os.RemoveAll(container.root); err != nil { return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err) }