From eb22239392c1507a629ed246c5d053e1001b7528 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Mon, 15 Jul 2024 07:47:54 +0100 Subject: [PATCH] fix: log output after context timeout (#2643) Still try to output the logs when the error which triggered is due to context timeout so that the user has a better chance to debug the issue. --- lifecycle.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lifecycle.go b/lifecycle.go index 7bc5d0bfdc..a40ebc0fac 100644 --- a/lifecycle.go +++ b/lifecycle.go @@ -370,7 +370,15 @@ func (c *DockerContainer) applyLifecycleHooks(ctx context.Context, logError bool if err := errors.Join(errs...); err != nil { if logError { - c.printLogs(ctx, err) + select { + case <-ctx.Done(): + // Context has timed out so need a new context to get logs. + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) + defer cancel() + c.printLogs(ctx, err) + default: + c.printLogs(ctx, err) + } } return err