Skip to content

Commit

Permalink
fix: log output after context timeout (testcontainers#2643)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stevenh authored Jul 15, 2024
1 parent 53b0ddf commit eb22239
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb22239

Please sign in to comment.