Skip to content

Commit

Permalink
[minor] Prefer signal.NotifyContext to signal.Notify in kanx (#3180)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdmanv authored Oct 10, 2024
1 parent 000ec09 commit 691adf3
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pkg/kanx/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ func NewServer() *Server {
}

func (s *Server) Serve(ctx context.Context, addr string) error {
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, syscall.SIGTERM, syscall.SIGINT)
ctx, can := signal.NotifyContext(ctx, syscall.SIGTERM, syscall.SIGINT)
defer can()
go func() {
select {
case sig := <-stopChan:
log.Info().Print("Gracefully stopping. Received Signal", field.M{"signal": sig})
case <-ctx.Done():
log.Info().Print("Gracefully stopping. Context canceled")
<-ctx.Done()
if err := ctx.Err(); err == context.Canceled {
log.Info().Print("Gracefully stopping. Parent context canceled")
} else {
log.Info().WithError(err).Print("Gracefully stopping.")
}
s.grpcs.GracefulStop()
}()
Expand Down

0 comments on commit 691adf3

Please sign in to comment.