fix close of closed channel

This commit is contained in:
Adphi 2020-11-15 15:51:29 +01:00
parent 9f5f03b862
commit c1d38dfbd0

View File

@ -239,23 +239,23 @@ func (s *service) Start() error {
} }
func (s *service) Stop() error { func (s *service) Stop() error {
defer close(s.closed)
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
if !s.running { if !s.running {
return nil return nil
} }
if err := s.opts.registry.Deregister(s.regSvc); err != nil {
logrus.Errorf("failed to deregister service: %v", err)
}
for i := range s.opts.beforeStop { for i := range s.opts.beforeStop {
if err := s.opts.beforeStop[i](); err != nil { if err := s.opts.beforeStop[i](); err != nil {
return err return err
} }
} }
if err := s.opts.registry.Deregister(s.regSvc); err != nil {
logrus.Errorf("failed to deregister service: %v", err)
}
defer close(s.closed)
s.server.GracefulStop() s.server.GracefulStop()
s.cancel()
s.running = false s.running = false
s.cancel()
for i := range s.opts.afterStop { for i := range s.opts.afterStop {
if err := s.opts.afterStop[i](); err != nil { if err := s.opts.afterStop[i](); err != nil {
return err return err