Skip to content

Commit

Permalink
Merge pull request containers#858 from giuseppe/retry-cgroup-delete
Browse files Browse the repository at this point in the history
cgroup: retry rmdir up to 5 seconds on EBUSY
Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
openshift-merge-robot authored and rhatdan committed Dec 14, 2021
2 parents 539c39c + cd108eb commit b730f04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ testing_task:
- export PATH="$PATH:$GOPATH/bin"
- gpg --batch --passphrase '' --quick-gen-key tester@localhost default default never
- make vendor
- make build-cross
- make build
- make install.tools
- make validate
Expand Down
21 changes: 17 additions & 4 deletions pkg/cgroups/cgroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"path/filepath"
"strconv"
"strings"
"time"

"github.com/containers/storage/pkg/unshare"
systemdDbus "github.com/coreos/go-systemd/v22/dbus"
"github.com/godbus/dbus/v5"
spec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)

var (
Expand Down Expand Up @@ -527,12 +529,23 @@ func rmDirRecursively(path string) error {
}
}
}
if err := os.Remove(path); err != nil {
if !os.IsNotExist(err) {
return errors.Wrapf(err, "remove %s", path)

attempts := 0
for {
err := os.Remove(path)
if err == nil || os.IsNotExist(err) {
return nil
}
if errors.Is(err, unix.EBUSY) {
// attempt up to 5 seconds if the cgroup is busy
if attempts < 500 {
time.Sleep(time.Millisecond * 10)
attempts++
continue
}
}
return errors.Wrapf(err, "remove %s", path)
}
return nil
}

// DeleteByPathConn deletes the specified cgroup path using the specified
Expand Down

0 comments on commit b730f04

Please sign in to comment.