Skip to content

Commit

Permalink
fix: don't attempt to start if controller allready running (#3632)
Browse files Browse the repository at this point in the history
We seem to have lost this check somewhere, and I keep hitting silent
failures when I have k3d up.
  • Loading branch information
stuartwdouglas authored Dec 9, 2024
1 parent 6cf0ce7 commit 4eaf042
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 13 additions & 2 deletions frontend/cli/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (d *devCmd) Run(
verbClient ftlv1connect.VerbServiceClient,
) error {
startTime := time.Now()
logger := log.FromContext(ctx)
ctx, cancel := context.WithCancel(ctx)
defer cancel()
if len(d.Build.Dirs) == 0 {
d.Build.Dirs = projConfig.AbsModuleDirs()
}
Expand Down Expand Up @@ -78,6 +81,7 @@ func (d *devCmd) Run(
return nil
}
statusManager := terminal.FromContext(ctx)
defer statusManager.Close()
starting := statusManager.NewStatus("\u001B[92mStarting FTL Server 🚀\u001B[39m")

bindAllocator, err := bind.NewBindAllocator(d.ServeCmd.Bind, 1)
Expand All @@ -102,7 +106,9 @@ func (d *devCmd) Run(
}

g.Go(func() error {
return d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, provisionerClient, schemaEventSourceFactory, verbClient, true, devModeEndpointUpdates)
err := d.ServeCmd.run(ctx, projConfig, cm, sm, optional.Some(controllerReady), true, bindAllocator, controllerClient, provisionerClient, schemaEventSourceFactory, verbClient, true, devModeEndpointUpdates)
cancel()
return err
})
}

Expand Down Expand Up @@ -133,5 +139,10 @@ func (d *devCmd) Run(
return engine.Dev(ctx, d.Watch)
})

return g.Wait()
err = g.Wait()
if err != nil {
logger.Errorf(err, "error during dev")
return fmt.Errorf("error during dev: %w", err)
}
return nil
}
14 changes: 11 additions & 3 deletions frontend/cli/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ func (s *serveCommonConfig) run(
// allow usage of --background and --stop together to "restart" the background process
_ = KillBackgroundServe(logger) //nolint:errcheck // ignore error here if the process is not running
}

_, err := controllerClient.Ping(ctx, connect.NewRequest(&ftlv1.PingRequest{}))
if err == nil {
// The controller is already running, bail out.
return fmt.Errorf("controller is already running")
}
if err := runInBackground(logger); err != nil {
return err
}
Expand All @@ -136,7 +140,11 @@ func (s *serveCommonConfig) run(
if s.Stop {
return KillBackgroundServe(logger)
}

_, err := controllerClient.Ping(ctx, connect.NewRequest(&ftlv1.PingRequest{}))
if err == nil {
// The controller is already running, bail out.
return fmt.Errorf("controller is already running")
}
if s.Provisioners > 0 {
logger.Debugf("Starting FTL with %d controller(s) and %d provisioner(s)", s.Controllers, s.Provisioners)
} else {
Expand All @@ -154,7 +162,7 @@ func (s *serveCommonConfig) run(
s.ObservabilityConfig.ExportOTEL = true
}
}
err := observability.Init(ctx, false, "", "ftl-serve", ftl.Version, s.ObservabilityConfig)
err = observability.Init(ctx, false, "", "ftl-serve", ftl.Version, s.ObservabilityConfig)
if err != nil {
return fmt.Errorf("observability init failed: %w", err)
}
Expand Down

0 comments on commit 4eaf042

Please sign in to comment.