From ab0c6137a296a22b20676351787903ddc2aa65a6 Mon Sep 17 00:00:00 2001 From: Xinfeng Liu Date: Fri, 8 Mar 2024 16:52:46 +0800 Subject: [PATCH] Add nil check in ListContainerStats On Windows, `ds.getContainerStats` could return nil for stopped containers. Signed-off-by: Xinfeng Liu --- core/stats.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/stats.go b/core/stats.go index bf3e28e80..2ea41fe8f 100644 --- a/core/stats.go +++ b/core/stats.go @@ -169,6 +169,9 @@ func (ds *dockerService) ContainerStats( if err != nil { return nil, err } + if stats == nil { + return nil, fmt.Errorf("stats for container with id %s not available", r.ContainerId) + } return &runtimeapi.ContainerStatsResponse{Stats: stats}, nil } @@ -232,7 +235,9 @@ func (ds *dockerService) ListContainerStats( return nil } mu.Lock() - results = append(results, stats) + if stats != nil { + results = append(results, stats) + } mu.Unlock() return nil })