fix registry check issue (#1067)

fix #1066

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2019-12-28 14:11:46 +03:00 committed by Asim Aslam
parent 61cde4a9f4
commit 943445270f

View File

@ -835,16 +835,19 @@ func (s *rpcServer) Start() error {
s.RLock() s.RLock()
registered := s.registered registered := s.registered
s.RUnlock() s.RUnlock()
if err = s.opts.RegisterCheck(s.opts.Context); err != nil && registered { rerr := s.opts.RegisterCheck(s.opts.Context)
if rerr != nil && registered {
log.Logf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err) log.Logf("Server %s-%s register check error: %s, deregister it", config.Name, config.Id, err)
// deregister self in case of error // deregister self in case of error
if err := s.Deregister(); err != nil { if err := s.Deregister(); err != nil {
log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err) log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
} }
} else { } else if rerr != nil && !registered {
if err := s.Register(); err != nil { log.Logf("Server %s-%s register check error: %s", config.Name, config.Id, err)
log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err) continue
} }
if err := s.Register(); err != nil {
log.Logf("Server %s-%s register error: %s", config.Name, config.Id, err)
} }
// wait for exit // wait for exit
case ch = <-s.exit: case ch = <-s.exit:
@ -854,9 +857,14 @@ func (s *rpcServer) Start() error {
} }
} }
// deregister self s.RLock()
if err := s.Deregister(); err != nil { registered := s.registered
log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err) s.RUnlock()
if registered {
// deregister self
if err := s.Deregister(); err != nil {
log.Logf("Server %s-%s deregister error: %s", config.Name, config.Id, err)
}
} }
s.Lock() s.Lock()