Merge pull request #47110 from corhere/backport-23.0/lock-container-when-deleting-root

[23.0 backport] Lock container when deleting its root directory
This commit is contained in:
Sebastiaan van Stijn 2024-01-19 12:11:16 +01:00 committed by GitHub
commit 190138d0ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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