Skip to content

Commit 6095984

Browse files
authored
fix: prevent graceful shutdown message on normal exit (#9244)
1 parent 77bab7b commit 6095984

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

cmd/trivy/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ func run() error {
4242
}
4343

4444
// Set up signal handling for graceful shutdown
45-
ctx, stop := commands.NotifyContext(context.Background())
46-
defer stop()
45+
ctx := commands.NotifyContext(context.Background())
4746

4847
app := commands.NewApp()
4948
return app.ExecuteContext(ctx)

pkg/commands/signal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// When a signal is received, Trivy will attempt to gracefully shut down by canceling
1616
// the context and waiting for all operations to complete. If users want to force an
1717
// immediate exit, they can send a second SIGINT or SIGTERM signal.
18-
func NotifyContext(parent context.Context) (context.Context, context.CancelFunc) {
18+
func NotifyContext(parent context.Context) context.Context {
1919
ctx, stop := signal.NotifyContext(parent, os.Interrupt, syscall.SIGTERM)
2020

2121
// Start a goroutine to handle cleanup when context is done
@@ -33,5 +33,5 @@ func NotifyContext(parent context.Context) (context.Context, context.CancelFunc)
3333
stop()
3434
}()
3535

36-
return ctx, stop
36+
return ctx
3737
}

0 commit comments

Comments
 (0)