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 8415e3d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion 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,7 +529,21 @@ func rmDirRecursively(path string) error {
}
}
}
if err := os.Remove(path); err != nil {

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
}
}
if !os.IsNotExist(err) {
return errors.Wrapf(err, "remove %s", path)
}
Expand Down

0 comments on commit 8415e3d

Please sign in to comment.