server/grpc: fix ordering of register and check for registered (#1338)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-03-13 01:04:11 +03:00 committed by GitHub
parent d8cfa7a295
commit 62a644ddd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -659,10 +659,12 @@ func (g *grpcServer) Register() error {
registered := g.registered registered := g.registered
g.Unlock() g.Unlock()
if !registered { if registered {
if logger.V(logger.InfoLevel, logger.DefaultLogger) { return nil
logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) }
}
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id)
} }
// create registry options // create registry options
@ -672,11 +674,6 @@ func (g *grpcServer) Register() error {
return err return err
} }
// already registered? don't need to register subscribers
if registered {
return nil
}
g.Lock() g.Lock()
defer g.Unlock() defer g.Unlock()
@ -787,10 +784,10 @@ func (g *grpcServer) Start() error {
g.RUnlock() g.RUnlock()
return nil return nil
} }
g.RUnlock()
config := g.Options() config := g.Options()
g.RUnlock()
// micro: config.Transport.Listen(config.Address) // micro: config.Transport.Listen(config.Address)
var ts net.Listener var ts net.Listener
@ -822,10 +819,11 @@ func (g *grpcServer) Start() error {
} }
g.Lock() g.Lock()
g.opts.Address = ts.Addr().String() g.opts.Address = ts.Addr().String()
subscribes := g.subscribers
g.Unlock() g.Unlock()
// only connect if we're subscribed // only connect if we're subscribed
if len(g.subscribers) > 0 { if len(subscribes) > 0 {
// connect to the broker // connect to the broker
if err := config.Broker.Connect(); err != nil { if err := config.Broker.Connect(); err != nil {
return err return err