Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
cgroups: add handling for EBUSY
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Sep 10, 2024
commit 0b263dcabed3265b42752367fd556b9d3d2fa828
27 changes: 23 additions & 4 deletions pkg/cgroups/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,30 @@ func createCgroupv2Path(path string) (deferredError error) {
// If the file itself is missing, return the original error.
return err
}
for _, ctr := range ctrs {
// Try to enable each controller individually, at least we can give a better error message if any fails.
if err := os.WriteFile(subtreeControl, []byte(fmt.Sprintf("+%s\n", ctr)), 0o755); err != nil {
return fmt.Errorf("enabling controller %s: %w", ctr, err)
repeatAttempts := 1000
for repeatAttempts > 0 {
// store the controllers that failed to be enabled, so we can retry them
newCtrs := [][]byte{}
for _, ctr := range ctrs {
// Try to enable each controller individually, at least we can give a better error message if any fails.
if err := os.WriteFile(subtreeControl, []byte(fmt.Sprintf("+%s\n", ctr)), 0o755); err != nil {
// The kernel can return EBUSY when a process was moved to a sub-cgroup
// and the controllers are enabled in its parent cgroup. Retry a few times when
// it happens.
if errors.Is(err, unix.EBUSY) {
newCtrs = append(newCtrs, ctr)
} else {
return fmt.Errorf("enabling controller %s: %w", ctr, err)
}
}
}
if len(newCtrs) == 0 {
err = nil
break
}
ctrs = newCtrs
repeatAttempts--
time.Sleep(time.Millisecond)
}
if err != nil {
return err
Expand Down