Prefer signal.NotifyContext over the manual implementation

This commit is contained in:
Zac Bergquist 2022-05-21 08:38:23 +02:00 committed by Zac Bergquist
parent 2396281028
commit dc08501c5f

View file

@ -722,15 +722,8 @@ func Run(args []string, opts ...cliOption) error {
utils.InitLogger(utils.LoggingForCLI, logrus.DebugLevel)
}
ctx, cancel := context.WithCancel(context.Background())
go func() {
exitSignals := make(chan os.Signal, 1)
signal.Notify(exitSignals, syscall.SIGTERM, syscall.SIGINT)
sig := <-exitSignals
log.Debugf("signal: %v", sig)
cancel()
}()
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancel()
cf.Context = ctx
cf.executablePath, err = os.Executable()