Avoid goroutine leak in server

This commit is contained in:
NicoMen 2018-09-06 14:24:03 +02:00 committed by Traefiker Bot
parent e4bb506ace
commit 74ace58ae1
4 changed files with 23 additions and 15 deletions

View file

@ -248,7 +248,9 @@ func (s *Server) Start() {
s.listenConfigurations(stop)
})
s.startProvider()
go s.listenSignals()
s.routinesPool.Go(func(stop chan bool) {
s.listenSignals(stop)
})
}
// StartWithContext starts the server and Stop/Close it when context is Done

View file

@ -447,10 +447,12 @@ func (s *Server) throttleProviderConfigReload(throttle time.Duration, publish ch
case <-stop:
return
case nextConfig := <-ring.Out():
publish <- nextConfig.(types.ConfigMessage)
if config, ok := nextConfig.(types.ConfigMessage); ok {
publish <- config
time.Sleep(throttle)
}
}
}
})
for {

View file

@ -13,9 +13,12 @@ func (s *Server) configureSignals() {
signal.Notify(s.signals, syscall.SIGUSR1)
}
func (s *Server) listenSignals() {
func (s *Server) listenSignals(stop chan bool) {
for {
sig := <-s.signals
select {
case <-stop:
return
case sig := <-s.signals:
switch sig {
case syscall.SIGUSR1:
log.Infof("Closing and re-opening log files for rotation: %+v", sig)
@ -32,3 +35,4 @@ func (s *Server) listenSignals() {
}
}
}
}

View file

@ -4,4 +4,4 @@ package server
func (s *Server) configureSignals() {}
func (s *Server) listenSignals() {}
func (s *Server) listenSignals(stop chan bool) {}