From b48e6025e6e4e48ff58b04fc28741d0e7b5672c4 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Thu, 18 Jul 2024 17:48:21 +0200 Subject: [PATCH] podman pod stats: fix pod rm race 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 --- pkg/domain/infra/abi/pods_stats.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/domain/infra/abi/pods_stats.go b/pkg/domain/infra/abi/pods_stats.go index 8ece02c2c6cc..841a8e297203 100644 --- a/pkg/domain/infra/abi/pods_stats.go +++ b/pkg/domain/infra/abi/pods_stats.go @@ -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" @@ -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]