aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCory Snider <csnider@mirantis.com>2022-05-09 15:06:37 -0400
committerCory Snider <csnider@mirantis.com>2022-08-24 14:59:08 -0400
commit18e322bc7c530d7b4393aca64e70dcad659621e3 (patch)
tree510cc25d434be892b503f3f7b837453c343d44d0
parent6a2f385aea283aee4cce84c01308f5e7906a1564 (diff)
Lock container when deleting its root directory
Attempting to delete the directory while another goroutine is concurrently executing a CheckpointTo() can fail on Windows due to file locking. As all callers of CheckpointTo() are required to hold the container lock, holding the lock while deleting the directory ensures that there will be no interference. Signed-off-by: Cory Snider <csnider@mirantis.com>
-rw-r--r--daemon/delete.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/daemon/delete.go b/daemon/delete.go
index db04705bef..e10c668352 100644
--- a/daemon/delete.go
+++ b/daemon/delete.go
@@ -138,7 +138,14 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, config ty
container.RWLayer = nil
}
- if err := containerfs.EnsureRemoveAll(container.Root); err != nil {
+ // Hold the container lock while deleting the container root directory
+ // so that other goroutines don't attempt to concurrently open files
+ // within it. Having any file open on Windows (without the
+ // FILE_SHARE_DELETE flag) will block it from being deleted.
+ container.Lock()
+ err := containerfs.EnsureRemoveAll(container.Root)
+ container.Unlock()
+ if err != nil {
err = errors.Wrapf(err, "unable to remove filesystem for %s", container.ID)
container.SetRemovalError(err)
return err