From ea60f1c448a0b0acb5eff97ac1242ab456b8e5c9 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 19 Dec 2022 17:46:22 +0100 Subject: [PATCH 1/2] Fix panic when checking service status There seems to be a race condition since a container starts running, till its state reports any health information. During this time the value obtained from the API is nil. Don't try to get the status from the healtcheck if that's the case. --- internal/stack/compose.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/stack/compose.go b/internal/stack/compose.go index 38b150df3..29aad5a7c 100644 --- a/internal/stack/compose.go +++ b/internal/stack/compose.go @@ -220,7 +220,7 @@ func newServiceStatus(description *docker.ContainerDescription) (*ServiceStatus, Status: description.State.Status, Version: getVersionFromDockerImage(description.Config.Image), } - if description.State.Status == "running" { + if description.State.Status == "running" && description.State.Health != nil { service.Status = fmt.Sprintf("%v (%v)", service.Status, description.State.Health.Status) } if description.State.Status == "exited" { From 0cd16572fa582da8f65255fb186517a92836b379 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Mon, 19 Dec 2022 21:34:35 +0100 Subject: [PATCH 2/2] Keep message if health is unknown --- internal/stack/compose.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/stack/compose.go b/internal/stack/compose.go index 29aad5a7c..a14a3aa22 100644 --- a/internal/stack/compose.go +++ b/internal/stack/compose.go @@ -220,8 +220,12 @@ func newServiceStatus(description *docker.ContainerDescription) (*ServiceStatus, Status: description.State.Status, Version: getVersionFromDockerImage(description.Config.Image), } - if description.State.Status == "running" && description.State.Health != nil { - service.Status = fmt.Sprintf("%v (%v)", service.Status, description.State.Health.Status) + if description.State.Status == "running" { + healthStatus := "unknown health" + if health := description.State.Health; health != nil { + healthStatus = health.Status + } + service.Status = fmt.Sprintf("%v (%v)", service.Status, healthStatus) } if description.State.Status == "exited" { service.Status = fmt.Sprintf("%v (%v)", service.Status, description.State.ExitCode)