From cbc695fed43629e88f71aab2495b380a20a25560 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 14 Dec 2021 16:09:33 +0100 Subject: [PATCH] cgroup: retry rmdir up to 5 seconds on EBUSY 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: https://github.com/containers/podman/issues/11946 Signed-off-by: Giuseppe Scrivano --- common/pkg/cgroups/cgroups.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/common/pkg/cgroups/cgroups.go b/common/pkg/cgroups/cgroups.go index d0bcd8bfd6..dcf675d1d4 100644 --- a/common/pkg/cgroups/cgroups.go +++ b/common/pkg/cgroups/cgroups.go @@ -11,6 +11,7 @@ import ( "path/filepath" "strconv" "strings" + "time" "github.com/containers/storage/pkg/unshare" systemdDbus "github.com/coreos/go-systemd/v22/dbus" @@ -18,6 +19,7 @@ import ( spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" ) var ( @@ -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