Merge pull request #12464 from giuseppe/fix-race-reading-cgroup-file

container, cgroup: detect pid termination
This commit is contained in:
OpenShift Merge Robot 2021-12-01 20:59:10 +01:00 committed by GitHub
commit ecc663097a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -939,6 +939,11 @@ func (c *Container) cGroupPath() (string, error) {
procPath := fmt.Sprintf("/proc/%d/cgroup", c.state.PID) procPath := fmt.Sprintf("/proc/%d/cgroup", c.state.PID)
lines, err := ioutil.ReadFile(procPath) lines, err := ioutil.ReadFile(procPath)
if err != nil { if err != nil {
// If the file doesn't exist, it means the container could have been terminated
// so report it.
if os.IsNotExist(err) {
return "", errors.Wrapf(define.ErrCtrStopped, "cannot get cgroup path unless container %s is running", c.ID())
}
return "", err return "", err
} }