Skip to content

Commit

Permalink
Resolves #261 - Fix SIGINT handler (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-r-west authored Dec 3, 2022
1 parent 4236c7d commit 1f69cd4
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/thediveo/enumflag"
"golang.org/x/time/rate"
"os"
"os/signal"
"syscall"
"time"

"github.com/caarlos0/env/v6"
Expand Down Expand Up @@ -151,9 +153,14 @@ func Execute() {
sigs := make(chan os.Signal, 1)
normalShutdown := make(chan bool, 1)
shutdownHandlerDone := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)

go func() {
exit := false
select {
case <-sigs:
case sig := <-sigs:
log.Warnf("Shutting down program due to signal [%v]", sig)
exit = true
case <-normalShutdown:
}

Expand All @@ -163,6 +170,11 @@ func Execute() {

httpclient.LogStats()
aliases.FlushAliases()

if exit {
os.Exit(3)
}

}()

err := RootCmd.Execute()
Expand Down

0 comments on commit 1f69cd4

Please sign in to comment.