From 0375e6d7d969a6bfab4326a744693ed7d2f4adf2 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Thu, 2 Mar 2017 15:38:52 -0700 Subject: [PATCH] fix panic on close --- services/alert/api.go | 4 +++- services/alert/service.go | 14 +++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/services/alert/api.go b/services/alert/api.go index 7135d99b0..743ebb317 100644 --- a/services/alert/api.go +++ b/services/alert/api.go @@ -113,7 +113,9 @@ func (s *apiServer) Open() error { } func (s *apiServer) Close() error { - s.HTTPDService.DelRoutes(s.routes) + if s.HTTPDService != nil { + s.HTTPDService.DelRoutes(s.routes) + } return nil } diff --git a/services/alert/service.go b/services/alert/service.go index cc4b2446e..15c8ec94c 100644 --- a/services/alert/service.go +++ b/services/alert/service.go @@ -155,6 +155,13 @@ func (s *Service) Open() error { return nil } +func (s *Service) Close() error { + s.mu.Lock() + defer s.mu.Unlock() + s.topics.Close() + return s.APIServer.Close() +} + func (s *Service) loadSavedHandlerSpecs() error { offset := 0 limit := 100 @@ -235,13 +242,6 @@ func (s *Service) loadSavedTopicStates() error { return nil } -func (s *Service) Close() error { - s.mu.Lock() - defer s.mu.Unlock() - s.topics.Close() - return s.APIServer.Close() -} - func validatePattern(pattern string) error { _, err := path.Match(pattern, "") return err