Use startGoroutine for signal handler
@@ -9,8 +9,12 @@ import (
func (s *Server) handleSignals() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
- go func() {
- for sig := range c {
+ s.startGoroutine(func() {
+ for {
+ select {
+ case <-s.shutdownCh:
+ return
+ case sig := <-c:
switch sig {
case os.Interrupt:
if err := s.Stop(); err != nil {
@@ -20,5 +24,6 @@ func (s *Server) handleSignals() {
os.Exit(0)
}
}
- }()
+ }
+ })
}
