Skip to content

Commit

Permalink
store: use system.EnsureRemoveAll to rm container
Browse files Browse the repository at this point in the history
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: containers/podman#11594

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Jan 14, 2022
1 parent 3c0dfaa commit 3e69d9a
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 3e69d9a

Please sign in to comment.