From f355900d344ec5e3c60ad46229f34856bb4adbe1 Mon Sep 17 00:00:00 2001 From: Mikhail Khachayants Date: Thu, 27 Oct 2022 22:39:24 +0300 Subject: [PATCH] Fix deadlock between 'podman ps' and 'container inspect' commands Fixes: #16326 [NO NEW TESTS NEEDED] Signed-off-by: Mikhail Khachayants --- libpod/pod_api.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/libpod/pod_api.go b/libpod/pod_api.go index 924d434361..7b143b478c 100644 --- a/libpod/pod_api.go +++ b/libpod/pod_api.go @@ -581,20 +581,15 @@ func (p *Pod) Status() (map[string]define.ContainerStatus, error) { } func containerStatusFromContainers(allCtrs []*Container) (map[string]define.ContainerStatus, error) { - // We need to lock all the containers - for _, ctr := range allCtrs { - ctr.lock.Lock() - defer ctr.lock.Unlock() - } - - // Now that all containers are locked, get their status status := make(map[string]define.ContainerStatus, len(allCtrs)) for _, ctr := range allCtrs { - if err := ctr.syncContainer(); err != nil { + state, err := ctr.State() + + if err != nil { return nil, err } - status[ctr.ID()] = ctr.state.State + status[ctr.ID()] = state } return status, nil