Skip to content

Commit

Permalink
fix: ftl dev hanging with --stop flag (#1087)
Browse files Browse the repository at this point in the history
I don't love this flow at the moment given how confusing the `--stop`
flag can be to use, but this fixes the issue. Hopefully, as we nail down
the ergonomics of how we want this to work we can help to avoid
confusion in the future.

Without FTL running:
```sh
ftl dev --stop --recreate examples/go
info: Starting FTL with 1 controller(s)
info:controller0: Web console available at: http://localhost:8892
info:time: Building module
info:time: Deploying module
...
```

If FTL is running in the background:
```sh
ftl dev --stop --recreate examples/go
info: `ftl serve` stopped (pid: 41006)
info: Starting FTL with 1 controller(s)
info:controller0: Web console available at: http://localhost:8892
info:time: Building module
...
```
  • Loading branch information
wesbillman authored Mar 14, 2024
1 parent 697def2 commit 39c50b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmd/ftl/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,17 @@ func (d *devCmd) Run(ctx context.Context) error {
g, ctx := errgroup.WithContext(ctx)

if !d.NoServe {
if d.ServeCmd.Stop {
err := d.ServeCmd.Run(ctx)
if err != nil {
return err
}
d.ServeCmd.Stop = false
}
if d.ServeCmd.isRunning(ctx, client) {
return errors.New("FTL is already running")
}

g.Go(func() error {
return d.ServeCmd.Run(ctx)
})
Expand Down
6 changes: 3 additions & 3 deletions cmd/ftl/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *serveCmd) Run(ctx context.Context) error {
if s.Stop {
// allow usage of --background and --stop together to "restart" the background process
// ignore error here if the process is not running
_ = killBackgroundProcess(logger)
_ = KillBackgroundServe(logger)
}

runInBackground(logger)
Expand All @@ -67,7 +67,7 @@ func (s *serveCmd) Run(ctx context.Context) error {
}

if s.Stop {
return killBackgroundProcess(logger)
return KillBackgroundServe(logger)
}

if s.isRunning(ctx, client) {
Expand Down Expand Up @@ -166,7 +166,7 @@ func runInBackground(logger *log.Logger) {
logger.Infof("`ftl serve` running in background with pid: %d", cmd.Process.Pid)
}

func killBackgroundProcess(logger *log.Logger) error {
func KillBackgroundServe(logger *log.Logger) error {
pidFilePath, err := pidFilePath()
if err != nil {
logger.Infof("No background process found")
Expand Down

0 comments on commit 39c50b6

Please sign in to comment.