Skip to content

Commit 901e112

Browse files
committed
PBM-397: cancel context on SIGINT and SIGKILL
to force agent status cleanup
1 parent 5098404 commit 901e112

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

cmd/pbm-agent/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
stdlog "log"
77
"os"
8+
"os/signal"
89
"runtime"
910
"strconv"
1011
"strings"
@@ -86,7 +87,7 @@ func runAgent(mongoURI string, dumpConns int) error {
8687
mtLog.SetDateFormat(log.LogTimeFormat)
8788
mtLog.SetVerbosity(&options.Verbosity{VLevel: mtLog.DebugLow})
8889

89-
ctx, cancel := context.WithCancel(context.Background())
90+
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
9091
defer cancel()
9192

9293
leadConn, err := connect.Connect(ctx, mongoURI, "pbm-agent")

pbm/ctrl/recv.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func ListenCmd(ctx context.Context, m connect.Client, cl <-chan struct{}) (<-cha
5454
)
5555
if err != nil {
5656
errc <- errors.Wrap(err, "watch the cmd stream")
57+
if errors.Is(err, context.Canceled) {
58+
return
59+
}
5760
continue
5861
}
5962

0 commit comments

Comments
 (0)