From 3e69d9a95b42d4efbbae73ddfe71c30c8d9970b6 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 14 Jan 2022 13:52:41 +0100 Subject: [PATCH] store: use system.EnsureRemoveAll to rm container if the container deletion fails with the simple os.RemoveAll(path), then attempt again using system.EnsureRemoveAll(path). The difference is that system.EnsureRemoveAll(path) tries to umount eventual mounts that are keeping the directory busy. It might help with: https://github.com/containers/podman/issues/11594 Signed-off-by: Giuseppe Scrivano --- store.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/store.go b/store.go index 0b1b0ea841..8ba04ab100 100644 --- a/store.go +++ b/store.go @@ -2501,23 +2501,29 @@ func (s *store) DeleteContainer(id string) error { gcpath := filepath.Join(s.GraphRoot(), middleDir, container.ID) wg.Add(1) go func() { - var err error - for attempts := 0; attempts < 50; attempts++ { - err = os.RemoveAll(gcpath) - if err == nil || !system.IsEBUSY(err) { - break - } - time.Sleep(time.Millisecond * 100) + defer wg.Done() + // attempt a simple rm -rf first + err := os.RemoveAll(gcpath) + if err == nil { + errChan <- nil + return } - errChan <- err - wg.Done() + // and if it fails get to the more complicated cleanup + errChan <- system.EnsureRemoveAll(gcpath) }() rcpath := filepath.Join(s.RunRoot(), middleDir, container.ID) wg.Add(1) go func() { - errChan <- os.RemoveAll(rcpath) - wg.Done() + defer wg.Done() + // attempt a simple rm -rf first + err := os.RemoveAll(rcpath) + if err == nil { + errChan <- nil + return + } + // and if it fails get to the more complicated cleanup + errChan <- system.EnsureRemoveAll(rcpath) }() go func() {