From c1d38dfbd0782309b24e34e027926561af419e7d Mon Sep 17 00:00:00 2001 From: Adphi Date: Sun, 15 Nov 2020 15:51:29 +0100 Subject: [PATCH] fix close of closed channel --- service/service.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/service/service.go b/service/service.go index 543b915..9003cdd 100644 --- a/service/service.go +++ b/service/service.go @@ -239,23 +239,23 @@ func (s *service) Start() error { } func (s *service) Stop() error { - defer close(s.closed) s.mu.Lock() defer s.mu.Unlock() if !s.running { 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 { if err := s.opts.beforeStop[i](); err != nil { 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.cancel() s.running = false + s.cancel() for i := range s.opts.afterStop { if err := s.opts.afterStop[i](); err != nil { return err