cgutil: handle panic from runc helper method (#16180)

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: https://github.com/opencontainers/runc/pull/3745

Closes #16179
This commit is contained in:
Seth Hoenig 2023-02-14 15:09:43 -06:00 committed by GitHub
parent d60c1393a3
commit 5d325decca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

3
.changelog/16180.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
cgutil: handle panic coming from runc helper method
```

View File

@ -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