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

View file

@ -13,21 +13,25 @@ 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
switch sig {
case syscall.SIGUSR1:
log.Infof("Closing and re-opening log files for rotation: %+v", sig)
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)
if s.accessLoggerMiddleware != nil {
if err := s.accessLoggerMiddleware.Rotate(); err != nil {
log.Errorf("Error rotating access log: %v", err)
if s.accessLoggerMiddleware != nil {
if err := s.accessLoggerMiddleware.Rotate(); err != nil {
log.Errorf("Error rotating access log: %v", err)
}
}
}
if err := log.RotateFile(); err != nil {
log.Errorf("Error rotating traefik log: %v", err)
if err := log.RotateFile(); err != nil {
log.Errorf("Error rotating traefik log: %v", err)
}
}
}
}

View file

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