Skip to content

Commit

Permalink
fix: return startup errors properly (#3682)
Browse files Browse the repository at this point in the history
We were returning "context cancelled" error before getting the errgroup
error that caused the context to be cancelled.
  • Loading branch information
jvmakine authored Dec 9, 2024
1 parent 4eaf042 commit f5faf04
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions frontend/cli/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,29 +362,32 @@ func (s *serveCommonConfig) run(
return nil
})
// Wait for controller to start, then run startup commands.
start := time.Now()
if err := waitForControllerOnline(ctx, s.StartupTimeout, controllerClient); err != nil {
return fmt.Errorf("controller failed to start: %w", err)
}
if s.Provisioners > 0 {
if err := rpc.Wait(ctx, backoff.Backoff{Max: s.StartupTimeout}, s.StartupTimeout, provisionerClient); err != nil {
return fmt.Errorf("provisioner failed to start: %w", err)
wg.Go(func() error {
start := time.Now()
if err := waitForControllerOnline(ctx, s.StartupTimeout, controllerClient); err != nil {
return fmt.Errorf("controller failed to start: %w", err)
}
}
logger.Infof("Controller started in %.2fs", time.Since(start).Seconds())

if len(projConfig.Commands.Startup) > 0 {
for _, cmd := range projConfig.Commands.Startup {
logger.Debugf("Executing startup command: %s", cmd)
if err := exec.Command(ctx, log.Info, ".", "bash", "-c", cmd).Run(); err != nil {
return fmt.Errorf("startup command failed: %w", err)
if s.Provisioners > 0 {
if err := rpc.Wait(ctx, backoff.Backoff{Max: s.StartupTimeout}, s.StartupTimeout, provisionerClient); err != nil {
return fmt.Errorf("provisioner failed to start: %w", err)
}
}
logger.Infof("Controller started in %.2fs", time.Since(start).Seconds())

if len(projConfig.Commands.Startup) > 0 {
for _, cmd := range projConfig.Commands.Startup {
logger.Debugf("Executing startup command: %s", cmd)
if err := exec.Command(ctx, log.Info, ".", "bash", "-c", cmd).Run(); err != nil {
return fmt.Errorf("startup command failed: %w", err)
}
}
}
}

if ch, ok := initialised.Get(); ok {
ch <- true
}
if ch, ok := initialised.Get(); ok {
ch <- true
}
return nil
})

if err := wg.Wait(); err != nil {
return fmt.Errorf("serve failed: %w", err)
Expand Down

0 comments on commit f5faf04

Please sign in to comment.