server.go: Stop periodically flushing on graceful shutdown
Server.Start starts a goroutine and a ticker to periodically call
Server.Flush(). This goroutine never terminates, which complicates
test output. Wait for both the Server.shutdown and ticker.C channels,
and correctly clean up if the server is shutting down.
@@ -514,9 +514,16 @@ func (s *Server) Start() {
ConsumePanic(s.Sentry, s.Statsd, s.Hostname, recover())
}()
ticker := time.NewTicker(s.interval)
- for range ticker.C {
+ for {
+ select {
+ case <-s.shutdown:
+ // stop flushing on graceful shutdown
+ ticker.Stop()
+ return
+ case <-ticker.C:
s.Flush()
}
+ }
}()
}
