Skip to content

Commit

Permalink
fix(server/v2): respect context cancellation in start command (#22346)
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-rushakoff authored Oct 23, 2024
1 parent 864ae34 commit bf12702
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/v2/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ func createStartCommand[T transaction.Tx](
go func() {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigCh
cancelFn()
cmd.Printf("caught %s signal\n", sig.String())
select {
case sig := <-sigCh:
cancelFn()
cmd.Printf("caught %s signal\n", sig.String())
case <-ctx.Done():
// If the root context is canceled (which is likely to happen in tests involving cobra commands),
// don't block waiting for the OS signal before stopping the server.
cancelFn()
}

if err := server.Stop(ctx); err != nil {
cmd.PrintErrln("failed to stop servers:", err)
Expand Down

0 comments on commit bf12702

Please sign in to comment.