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 <gabriel@opdemand.com> (github: gabrtv)
| ... | ... |
@@ -272,6 +272,10 @@ func (daemon *Daemon) Destroy(container *Container) error {
|
| 272 | 272 |
return err |
| 273 | 273 |
} |
| 274 | 274 |
|
| 275 |
+ // Deregister the container before removing its directory, to avoid race conditions |
|
| 276 |
+ daemon.idIndex.Delete(container.ID) |
|
| 277 |
+ daemon.containers.Remove(element) |
|
| 278 |
+ |
|
| 275 | 279 |
if err := daemon.driver.Remove(container.ID); err != nil {
|
| 276 | 280 |
return fmt.Errorf("Driver %s failed to remove root filesystem %s: %s", daemon.driver, container.ID, err)
|
| 277 | 281 |
} |
| ... | ... |
@@ -285,9 +289,6 @@ func (daemon *Daemon) Destroy(container *Container) error {
|
| 285 | 285 |
utils.Debugf("Unable to remove container from link graph: %s", err)
|
| 286 | 286 |
} |
| 287 | 287 |
|
| 288 |
- // Deregister the container before removing its directory, to avoid race conditions |
|
| 289 |
- daemon.idIndex.Delete(container.ID) |
|
| 290 |
- daemon.containers.Remove(element) |
|
| 291 | 288 |
if err := os.RemoveAll(container.root); err != nil {
|
| 292 | 289 |
return fmt.Errorf("Unable to remove filesystem for %v: %v", container.ID, err)
|
| 293 | 290 |
} |