From 80008d7253a088a325ca0ad1f08fa88ec28f073b Mon Sep 17 00:00:00 2001 From: lfbzhm Date: Sun, 10 Nov 2024 02:08:18 +0000 Subject: [PATCH] libct/cg: fix an error of cgroup path removal For cgroup path removal, when we try a fast way to remove the cgroup path, there may be a small possibility race to return an error, though the path was removed successfully, for example: EINTR, or other errors. Then we will fall back to the traditional path walk removal, but there is a regression if the path has been sucessfully removed, which was introduced by d3d7f7d in #4102. We should erase the ErrNotExist error when we open the cgroup path. Signed-off-by: lfbzhm --- libcontainer/cgroups/utils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libcontainer/cgroups/utils.go b/libcontainer/cgroups/utils.go index a05945cba6c..695628bf939 100644 --- a/libcontainer/cgroups/utils.go +++ b/libcontainer/cgroups/utils.go @@ -257,14 +257,20 @@ func RemovePath(path string) error { } infos, err := os.ReadDir(path) - if err != nil && !os.IsNotExist(err) { + if err != nil { + if os.IsNotExist(err) { + // Please keep this error eraser, or else it will return ErrNotExist + // for cgroupv2. + // Please see https://github.com/opencontainers/runc/issues/4518 + return nil + } return err } for _, info := range infos { if info.IsDir() { // We should remove subcgroup first. if err = RemovePath(filepath.Join(path, info.Name())); err != nil { - break + return err } } }