Skip to content

Commit

Permalink
podman pod stats: fix pod rm race
Browse files Browse the repository at this point in the history
If a pod is removed when calling podman pod stats there is a race where
the command might fail with no such pod. This is not a user error, like
the ps/ls command skip it and move to the next one.

Fixes #23327

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jul 18, 2024
1 parent e1caf80 commit 182224d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/domain/infra/abi/pods_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/containers/common/pkg/cgroups"
"github.com/containers/podman/v5/libpod"
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/containers/podman/v5/pkg/rootless"
"github.com/docker/go-units"
Expand Down Expand Up @@ -39,6 +40,10 @@ func (ic *ContainerEngine) podsToStatsReport(pods []*libpod.Pod) ([]*entities.Po
for i := range pods { // Access by index to prevent potential loop-variable leaks.
podStats, err := pods[i].GetPodStats(nil)
if err != nil {
// pod was removed, skip it
if errors.Is(err, define.ErrNoSuchPod) {
continue
}
return nil, err
}
podID := pods[i].ID()[:12]
Expand Down

0 comments on commit 182224d

Please sign in to comment.