Skip to content

Commit 6f5001d

Browse files
committed
cg2: Don't read cgroup.procs when deleting threaded cg
Reading cgroup.procs seems to return ENOTSUPP when threaded, so check the type of the cg when going to delete and read the relevant file. Signed-off-by: Danny Canter <[email protected]>
1 parent 1e05688 commit 6f5001d

2 files changed

Lines changed: 25 additions & 5 deletions

File tree

cgroup2/manager.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,33 @@ func (c *Manager) fallbackKill() error {
468468
}
469469

470470
func (c *Manager) Delete() error {
471-
// kernel prevents cgroups with running process from being removed, check the tree is empty
472-
processes, err := c.Procs(true)
471+
var (
472+
tasks []uint64
473+
threaded bool
474+
)
475+
// Kernel prevents cgroups with running process from being removed,
476+
// check the tree is empty.
477+
//
478+
// Pick the right file to read based on the cgs type.
479+
cgType, err := c.GetType()
480+
if err != nil {
481+
if !os.IsNotExist(err) {
482+
return err
483+
}
484+
} else {
485+
threaded = cgType == Threaded
486+
}
487+
488+
if threaded {
489+
tasks, err = c.Threads(true)
490+
} else {
491+
tasks, err = c.Procs(true)
492+
}
473493
if err != nil {
474494
return err
475495
}
476-
if len(processes) > 0 {
477-
return fmt.Errorf("cgroups: unable to remove path %q: still contains running processes", c.path)
496+
if len(tasks) > 0 {
497+
return fmt.Errorf("cgroups: unable to remove path %q: still contains running tasks", c.path)
478498
}
479499
return remove(c.path)
480500
}

cgroup2/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func TestCgroupType(t *testing.T) {
284284
manager, err := NewManager(defaultCgroup2Path, "/test-type", ToResources(&specs.LinuxResources{}))
285285
require.NoError(t, err)
286286
t.Cleanup(func() {
287-
os.RemoveAll(manager.path)
287+
_ = manager.Delete()
288288
})
289289

290290
cgType, err := manager.GetType()

0 commit comments

Comments
 (0)