Close server is reverse order that it was started

The server was closing by stopping the most depended on services first
which causes various panics while higher level services are still processing
task when the server closes.

Fixes #3881
pull/4005/head
Jason Wilder 2015-09-04 16:29:59 -06:00
parent ab0b2231a6
commit dabb01691e
1 changed files with 19 additions and 10 deletions

View File

@ -382,23 +382,32 @@ func (s *Server) Open() error {
func (s *Server) Close() error {
stopProfile()
// Close the listener first to stop any new connections
if s.Listener != nil {
s.Listener.Close()
}
if s.MetaStore != nil {
s.MetaStore.Close()
}
if s.TSDBStore != nil {
s.TSDBStore.Close()
}
if s.HintedHandoff != nil {
s.HintedHandoff.Close()
// Close services to any inflight requests can be stopped
for _, service := range s.Services {
service.Close()
}
if s.Monitor != nil {
s.Monitor.Close()
}
for _, service := range s.Services {
service.Close()
if s.HintedHandoff != nil {
s.HintedHandoff.Close()
}
// Close the TSDBStore, no more reads or writes at this point
if s.TSDBStore != nil {
s.TSDBStore.Close()
}
// Finally close the meta-store since everything else depends on it
if s.MetaStore != nil {
s.MetaStore.Close()
}
close(s.closing)