Skip to content

Commit 2a96e6b

Browse files
committed
Signals: Add cause to signal context cancel
Signed-off-by: joshvanl <[email protected]>
1 parent c90b807 commit 2a96e6b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

signals/signals.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package signals
1515

1616
import (
1717
"context"
18+
"fmt"
1819
"os"
1920
"os/signal"
2021

@@ -37,14 +38,14 @@ func Context() context.Context {
3738
// panics when called twice
3839
close(onlyOneSignalHandler)
3940

40-
ctx, cancel := context.WithCancel(context.Background())
41+
ctx, cancel := context.WithCancelCause(context.Background())
4142
sigCh := make(chan os.Signal, 1)
4243
signal.Notify(sigCh, shutdownSignals...)
4344

4445
go func() {
4546
sig := <-sigCh
4647
log.Infof(`Received signal '%s'; beginning shutdown`, sig)
47-
cancel()
48+
cancel(fmt.Errorf("cancelling context, received signal %s", sig))
4849
sig = <-sigCh
4950
log.Fatalf(
5051
`Received signal '%s' during shutdown; exiting immediately`,

0 commit comments

Comments
 (0)