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

cgroup2: Manager.Delete: handle both "threaded" and "domain threaded" #358

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
12 changes: 4 additions & 8 deletions cgroup2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,10 +472,6 @@ func (c *Manager) fallbackKill() error {
}

func (c *Manager) Delete() error {
var (
tasks []uint64
threaded bool
)
// Kernel prevents cgroups with running process from being removed,
// check the tree is empty.
//
Expand All @@ -485,13 +481,13 @@ func (c *Manager) Delete() error {
if !os.IsNotExist(err) {
return err
}
} else {
threaded = cgType == Threaded
}

if threaded {
var tasks []uint64
switch cgType {
case Threaded, DomainThreaded:
tasks, err = c.Threads(true)
} else {
default:
tasks, err = c.Procs(true)
Comment on lines +488 to 491
Copy link
Member Author

Choose a reason for hiding this comment

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

Alternative could be to just to try either if we get anything in return?

if tasks, _ := c.Threads(true); len(tasks) > 0 {
	return fmt.Errorf("cgroups: unable to remove path %q: still contains running tasks", c.path)
}
if tasks, _ := c.Procs(true); len(tasks) > 0 {
	return fmt.Errorf("cgroups: unable to remove path %q: still contains running tasks", c.path)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, not sure if that makes sense. Looking at Procs and Threads, they both call getTasks under the hood; if the above does make sense, I guess that function could possibly accept both cgroupProcs and cgroupThreads to get "any".

}
if err != nil {
Expand Down