Skip to content

Commit

Permalink
container, cgroup: detect pid termination
Browse files Browse the repository at this point in the history
If the /proc/$PID/cgroup file doesn't exist, then it is likely the
container was terminated in the meanwhile so report ErrCtrStopped that
is already handled instead of ENOENT.

commit a66f40b introduced the regression.

Closes: containers#12457

[NO NEW TESTS NEEDED] it solves a race in the CI that is difficult to reproduce.

Signed-off-by: Giuseppe Scrivano <[email protected]>
  • Loading branch information
giuseppe committed Dec 1, 2021
1 parent 295a6f7 commit 0afaf78
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,11 @@ func (c *Container) cGroupPath() (string, error) {
procPath := fmt.Sprintf("/proc/%d/cgroup", c.state.PID)
lines, err := ioutil.ReadFile(procPath)
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
}

Expand Down

0 comments on commit 0afaf78

Please sign in to comment.