Skip to content

Commit 2461acd

Browse files
Handle SIGINT/SIGTERM to allow graceful shutdown (#28)
## Problem The breakpoint CLI ignored interrupt signals (SIGINT/SIGTERM) because the root context was a plain `context.Background()` with no signal handling. This meant Ctrl+C and GitHub Actions cancellation had no effect — the process would keep running until the timer expired. ## Fix Use `signal.NotifyContext` in `main.go` to cancel the root context on SIGINT and SIGTERM. This propagates through all subcommands (`wait`, `hold`, etc.) via their `<-ctx.Done()` selects. Co-authored-by: Amp <amp@ampcode.com>
1 parent f68173c commit 2461acd

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ jobs:
4646
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
4747
with:
4848
duration: 30m
49-
authorized-users: edganiukov,hugosantos,n-g,htr,nichtverstehen,gmichelo
49+
authorized-users: hugosantos,n-g,htr
5050
slack-announce-channel: "#ci"

.github/workflows/checks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ jobs:
4040
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
4141
with:
4242
duration: 30m
43-
authorized-users: edganiukov,hugosantos,n-g,htr,nichtverstehen,gmichelo
43+
authorized-users: hugosantos,n-g,htr
4444
slack-announce-channel: "#ci"

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ jobs:
4646
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
4747
with:
4848
duration: 30m
49-
authorized-users: edganiukov,hugosantos,n-g,htr,nichtverstehen,gmichelo
49+
authorized-users: hugosantos,n-g,htr
5050
slack-announce-channel: "#ci"

cmd/breakpoint/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"os/signal"
8+
"syscall"
79

810
"github.com/spf13/cobra"
911
"namespacelabs.dev/breakpoint/pkg/blog"
@@ -20,7 +22,10 @@ func main() {
2022

2123
l := blog.New()
2224

23-
err := rootCmd.ExecuteContext(l.WithContext(context.Background()))
25+
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
26+
defer stop()
27+
28+
err := rootCmd.ExecuteContext(l.WithContext(ctx))
2429
if err != nil {
2530
fmt.Fprintln(os.Stderr, err)
2631
os.Exit(1)

0 commit comments

Comments
 (0)