From 55749af0c7c7d8fed8e095a649d216450313fbdb Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Fri, 19 Jul 2024 13:21:34 +0200 Subject: [PATCH] podman stats: fix race when ctr process exists stats read from the cgroup, and in order to know the cgroup we check the pid for the cgroup. However there is a window where the pid exited and podman did not yet updated its internal state. In this case the code returns ErrCtrStopped so we should ignore this error as well. Fixes #23334 Signed-off-by: Paul Holzinger --- pkg/domain/infra/abi/containers.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index b350c68e13..e2356e9d6b 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -1581,7 +1581,14 @@ func (ic *ContainerEngine) ContainerStats(ctx context.Context, namesOrIds []stri for _, ctr := range containers { stats, err := ctr.GetContainerStats(containerStats[ctr.ID()]) if err != nil { - if queryAll && (errors.Is(err, define.ErrCtrRemoved) || errors.Is(err, define.ErrNoSuchCtr) || errors.Is(err, define.ErrCtrStateInvalid)) { + if queryAll && + // All these errors might happen while we get stats, when we list all + // they must be skipped as they cause podman stats to stop and error otherwise. + // ErrCtrStopped can happen when the container process exited before we could + // update the container state + // https://github.com/containers/podman/issues/23334 + (errors.Is(err, define.ErrCtrRemoved) || errors.Is(err, define.ErrNoSuchCtr) || + errors.Is(err, define.ErrCtrStateInvalid) || errors.Is(err, define.ErrCtrStopped)) { continue } return nil, err