From 0caec9ef7ac1256a81df189fcfe9986c550cbf13 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Thu, 8 Oct 2026 09:19:20 +0200 Subject: [PATCH] fix(start): list containers before opening the --wait-timeout window The final readiness check opened its --wait-timeout window before re-listing the project's containers, so a slow daemon listing could exhaust the budget and report "application not healthy" before waitDependencies had polled once. List first on the caller's context, then derive the timed one, as the imperative start path did. Signed-off-by: Nicolas De Loof --- pkg/compose/start.go | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/compose/start.go b/pkg/compose/start.go index 2210b44cf..1ac7028a2 100644 --- a/pkg/compose/start.go +++ b/pkg/compose/start.go @@ -115,7 +115,22 @@ func (s *composeService) start(ctx context.Context, projectName string, options return nil } - // origCtx is kept so the two DeadlineExceeded checks below can tell this + // getContainers filters on ConfigHashLabel presence (getDefaultFilters), + // which every service container carries and hook runners deliberately do + // not: pre_start runners never leak into this verification at the source + // (isNotHookContainer downstream stays as defense-in-depth). ScopeStart + // never creates a container, so this re-listing exists only to give the + // readiness check a fresh view of the daemon, not to discover new IDs the + // pre-execution observed snapshot wouldn't have (contrast upDetached, + // which can create or recreate containers). It runs before the + // --wait-timeout window opens, so daemon-listing latency never eats into + // the budget the readiness polling is owed. + containers, err := s.getContainers(ctx, project.Name, oneOffExclude, true) + if err != nil { + return err + } + + // origCtx is kept so the DeadlineExceeded check below can tell this // fresh window expiring (origCtx still fine) apart from origCtx's own, // independent deadline propagating through the derived one (origCtx // already done) -- same reasoning as upDetached. @@ -126,22 +141,6 @@ func (s *composeService) start(ctx context.Context, projectName string, options defer cancel() } - // getContainers filters on ConfigHashLabel presence (getDefaultFilters), - // which every service container carries and hook runners deliberately do - // not: pre_start runners never leak into this verification at the source - // (isNotHookContainer downstream stays as defense-in-depth). ScopeStart - // never creates a container, so this re-listing exists only to open a - // fresh WaitTimeout window, not to discover new IDs the pre-execution - // observed snapshot wouldn't have (contrast upDetached, which can create - // or recreate containers). - containers, err := s.getContainers(ctx, project.Name, oneOffExclude, true) - if err != nil { - if options.WaitTimeout > 0 && origCtx.Err() == nil && errors.Is(ctx.Err(), context.DeadlineExceeded) { - return fmt.Errorf("application not healthy after %s", options.WaitTimeout) - } - return err - } - depends := types.DependsOnConfig{} for _, svc := range project.Services { depends[svc.Name] = types.ServiceDependency{