Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libct/cg: fix an error of cgroup path removal #4520

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ func rmdir(path string, retry bool) error {
tries := 10

again:
// If we remove a non-exist dir in a ro mount point, it will
// return EROFS in `unix.Rmdir`, so we need to check first.
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil
}
err := unix.Rmdir(path)
switch err { // nolint:errorlint // unix errors are bare
case nil, unix.ENOENT:
Expand Down Expand Up @@ -257,15 +262,22 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to have a bats test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it’s hard to simulate the similar error.
But maybe we can split this func, and add a go unit test. I don’t know it’s worth to do or not. But we should verify this patch is correct or not at first.

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
}
if !info.IsDir() {
continue
}
// We should remove subcgroup first.
if err = RemovePath(filepath.Join(path, info.Name())); err != nil {
return err
}
}
if err == nil {
Expand Down
Loading