@@ -20,40 +20,31 @@ package utils
2020import (
2121 "os"
2222 "os/signal"
23- "sync"
2423 "syscall"
2524
2625 log "github.com/sirupsen/logrus"
2726)
2827
2928var (
30- registeredChannels []chan struct {}
31- chanMutex sync.Mutex
29+ exitChannel chan struct {}
3230)
3331
34- func RegisterExitChannel (ch chan struct {}) {
35- chanMutex .Lock ()
36- defer chanMutex .Unlock ()
37- registeredChannels = append (registeredChannels , ch )
32+ func ExitChannel () <- chan struct {} {
33+ return exitChannel
3834}
3935
4036func SetupElegantExit () {
4137 log .Debugf ("entering SetupElegantExit" )
4238 // handle elegant exit; create support for channels of go routines that want to exit cleanly
43- registeredChannels = make ([] chan struct {}, 0 )
39+ exitChannel = make (chan struct {})
4440 exitSigChan := make (chan os.Signal , 1 )
4541 log .Debugf ("registered exit signal channel" )
4642 signal .Notify (exitSigChan , syscall .SIGINT , syscall .SIGTERM )
4743 go func () {
4844 // wait for exit signal; then stop all the other go functions
4945 sig := <- exitSigChan
5046 log .Debugf ("received exit signal = %v" , sig )
51- chanMutex .Lock ()
52- defer chanMutex .Unlock ()
53- // exit signal received; stop other go functions
54- for _ , ch := range registeredChannels {
55- close (ch )
56- }
47+ close (exitChannel )
5748 log .Debugf ("exiting SetupElegantExit go function" )
5849 }()
5950 log .Debugf ("exiting SetupElegantExit" )
0 commit comments