mirror of
https://github.com/linka-cloud/grpc.git
synced 2024-11-22 02:46:25 +00:00
fix close of closed channel
This commit is contained in:
parent
9f5f03b862
commit
c1d38dfbd0
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user