Skip to content

Commit

Permalink
cgutil: handle panic from runc helper method (#16180)
Browse files Browse the repository at this point in the history
This PR wraps the cgroups.IsCgroup2UnifiedMode() helper method from
runc in a defer/recover block because it might panic in some cases.

Upstream fix in: opencontainers/runc#3745

Closes #16179
  • Loading branch information
shoenig committed Feb 14, 2023
1 parent 7ffb0b1 commit 36a9886
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/16180.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
cgutil: handle panic coming from runc helper method
```
14 changes: 13 additions & 1 deletion client/lib/cgutil/cgutil_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ import (
// cgroups.v1
//
// This is a read-only value.
var UseV2 = cgroups.IsCgroup2UnifiedMode()
var UseV2 = safelyDetectUnifiedMode()

// Currently it is possible for the runc utility function to panic
// https://github.com/opencontainers/runc/pull/3745
func safelyDetectUnifiedMode() (result bool) {
defer func() {
if r := recover(); r != nil {
result = false
}
}()
result = cgroups.IsCgroup2UnifiedMode()
return
}

// GetCgroupParent returns the mount point under the root cgroup in which Nomad
// will create cgroups. If parent is not set, an appropriate name for the version
Expand Down

0 comments on commit 36a9886

Please sign in to comment.