Skip to content

Commit

Permalink
cgroup: retry rmdir up to 5 seconds on EBUSY
Browse files Browse the repository at this point in the history
on a busy system, the conmon process could take longer to complete or
to be reaped by the parent, leaving the cgroup busy.  If the rmdir
fails with EBUSY, try again up to 5 seconds before reporting an
error.

Closes: containers/podman#11946

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Dec 14, 2021
1 parent bd6e86d commit df9a7b3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 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,10 +529,22 @@ 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
}
Expand Down

0 comments on commit df9a7b3

Please sign in to comment.