Skip to content

Commit 4b231e6

Browse files
committed
fix: handle nil Health state in docker container handler
Container.State.Health can be nil when no health check is configured. Check for nil before accessing .Status to prevent panic. Fixes nil pointer dereference in newDockerContainerHandler when inspecting containers without health checks. Signed-off-by: Davanum Srinivas <[email protected]>
1 parent 67e640d commit 4b231e6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

container/docker/handler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,13 @@ func newDockerContainerHandler(
199199
rootfsStorageDir: rootfsStorageDir,
200200
envs: make(map[string]string),
201201
labels: ctnr.Config.Labels,
202-
healthStatus: ctnr.State.Health.Status,
203202
includedMetrics: metrics,
204203
zfsParent: zfsParent,
205204
}
205+
// Health status may be nil if no health check is configured
206+
if ctnr.State.Health != nil {
207+
handler.healthStatus = ctnr.State.Health.Status
208+
}
206209
// Timestamp returned by Docker is in time.RFC3339Nano format.
207210
handler.creationTime, err = time.Parse(time.RFC3339Nano, ctnr.Created)
208211
if err != nil {

0 commit comments

Comments
 (0)