Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions pkg/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,20 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
globalCtx, cancel := context.WithCancel(ctx)
defer cancel()

// startCtx keeps service startup isolated from parent cancellation,
// while still allowing the interactive detach action to interrupt
// startup/wait and return control to the user.
startCtx, cancelStart := context.WithCancel(context.WithoutCancel(ctx))
defer cancelStart()

var isDetached atomic.Bool

if navigationMenu != nil {
navigationMenu.EnableDetach(cancel)
navigationMenu.EnableDetach(func() {
isDetached.Store(true)
cancelStart()
cancel()
})
}

var (
Expand Down Expand Up @@ -283,8 +295,12 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
})

// We use the parent context without cancellation as we manage sigterm to stop the stack
err = s.start(context.WithoutCancel(ctx), project.Name, options.Start, printer.HandleEvent)
err = s.start(startCtx, project.Name, options.Start, printer.HandleEvent)
if err != nil && !isTerminated.Load() { // Ignore error if the process is terminated
if isDetached.Load() && errors.Is(err, context.Canceled) {
return nil
}

cancel()
_ = eg.Wait()
return err
Expand Down