Skip to content

Commit

Permalink
libct/cg: fix an error of cgroup path removal
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
lifubang committed Nov 11, 2024
1 parent 3a09973 commit 80008d7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 80008d7

Please sign in to comment.