From 40334d570a602e60dc10076b11e81c34141ee769 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Mon, 9 Nov 2020 18:19:31 +0100 Subject: [PATCH] Avoid nil pointer when reading logs of a just terminated container. Hit this when following logs of a container restarted with a health check: ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x168771e] goroutine 1 [running]: github.com/docker/compose-cli/aci.getACIContainerLogs(0x2d85260, 0xc000526c60, 0xc0001465a0, 0x24, 0xc0004f4da0, 0xa, 0xc0004f4db0, 0x7, 0x7ffeefbffab2, 0xb, ...) github.com/docker/compose-cli/aci/aci.go:285 +0x1fe github.com/docker/compose-cli/aci.streamLogs(0x2d85260, 0xc000526c60, 0xc0001465a0, 0x24, 0xc0004f4da0, 0xa, 0xc0004f4db0, 0x7, 0x7ffeefbffab2, 0xb, ...) github.com/docker/compose-cli/aci/aci.go:297 +0x2e5 ``` Signed-off-by: Guillaume Tardif --- aci/aci.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aci/aci.go b/aci/aci.go index 12442313d..04e612ee4 100644 --- a/aci/aci.go +++ b/aci/aci.go @@ -282,6 +282,9 @@ func getACIContainerLogs(ctx context.Context, aciContext store.AciContext, conta if err != nil { return "", fmt.Errorf("cannot get container logs: %v", err) } + if logs.Content == nil { + return "", nil + } return *logs.Content, err }