Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server/v2): respect context cancellation in start command #22346

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from 1 commit
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
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 cancelled (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
Loading