Skip to content

Commit

Permalink
store: retry RemoveAll on EBUSY
Browse files Browse the repository at this point in the history
when running on NFS, a RemoveAll could cause EBUSY because of some
unlinked files that are still kept open and "silly renamed" to
.nfs$ID.

These files could be kept open by conmon and the issue is addressed
by: containers/conmon#300

Before failing, attempt a few more times.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Sep 30, 2021
1 parent b2e6925 commit e268f49
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pkg/system/syscall_unix.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// +build linux freebsd
// +build linux freebsd darwin

package system

import "golang.org/x/sys/unix"
import (
"github.com/pkg/errors"
"golang.org/x/sys/unix"
)

// Unmount is a platform-specific helper function to call
// the unmount syscall.
Expand All @@ -15,3 +18,8 @@ func Unmount(dest string) error {
func CommandLineToArgv(commandLine string) ([]string, error) {
return []string{commandLine}, nil
}

// IsEBUSY checks if the specified error is EBUSY.
func IsEBUSY(err error) bool {
return errors.Is(err, unix.EBUSY)
}
5 changes: 5 additions & 0 deletions pkg/system/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,8 @@ func HasWin32KSupport() bool {
// APIs.
return ntuserApiset.Load() == nil
}

// IsEBUSY checks if the specified error is EBUSY.
func IsEBUSY(err error) bool {
return false
}
11 changes: 10 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/containers/storage/pkg/parsers"
"github.com/containers/storage/pkg/stringid"
"github.com/containers/storage/pkg/stringutils"
"github.com/containers/storage/pkg/system"
"github.com/containers/storage/types"
"github.com/hashicorp/go-multierror"
digest "github.com/opencontainers/go-digest"
Expand Down Expand Up @@ -2498,7 +2499,15 @@ func (s *store) DeleteContainer(id string) error {
gcpath := filepath.Join(s.GraphRoot(), middleDir, container.ID)
wg.Add(1)
go func() {
errChan <- os.RemoveAll(gcpath)
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)
}
errChan <- err
wg.Done()
}()

Expand Down

0 comments on commit e268f49

Please sign in to comment.