From 309618ce0839da6ec6b1d4d90a9666ff19c74151 Mon Sep 17 00:00:00 2001 From: Robin Stumm Date: Thu, 21 Jul 2022 13:09:48 +0200 Subject: [PATCH] fix container stats endpoint response handling Podman 4.1.1 changed the REST API HTTP status for stopped containers from 404 to 200. fix #182 --- api/container_stats.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/api/container_stats.go b/api/container_stats.go index 5defc332..52a99395 100644 --- a/api/container_stats.go +++ b/api/container_stats.go @@ -38,6 +38,12 @@ func (c *API) ContainerStats(ctx context.Context, name string) (Stats, error) { if err != nil { return stats, err } + + // Since podman 4.1.1, an empty 200 response is returned for stopped containers. + if len(body) == 0 { + return stats, ContainerNotFound + } + err = json.Unmarshal(body, &stats) if err != nil { return stats, err