Skip to content

Commit

Permalink
PBM-397: cancel context on SIGINT and SIGKILL
Browse files Browse the repository at this point in the history
to force agent status cleanup
  • Loading branch information
defbin committed Sep 25, 2024
1 parent c64a6e1 commit b390ca9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/pbm-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
stdlog "log"
"os"
"os/signal"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -86,7 +87,7 @@ func runAgent(mongoURI string, dumpConns int) error {
mtLog.SetDateFormat(log.LogTimeFormat)
mtLog.SetVerbosity(&options.Verbosity{VLevel: mtLog.DebugLow})

ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill)
defer cancel()

leadConn, err := connect.Connect(ctx, mongoURI, "pbm-agent")
Expand Down
3 changes: 3 additions & 0 deletions pbm/ctrl/recv.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func ListenCmd(ctx context.Context, m connect.Client, cl <-chan struct{}) (<-cha
)
if err != nil {
errc <- errors.Wrap(err, "watch the cmd stream")
if errors.Is(err, context.Canceled) {
return
}
continue
}

Expand Down

0 comments on commit b390ca9

Please sign in to comment.