From d83b49c634946e96eb9496e312f9a5ffe2383337 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 13 Mar 2020 01:04:11 +0300 Subject: [PATCH] server/grpc: fix ordering of register and check for registered (#1338) Signed-off-by: Vasiliy Tolstov --- grpc.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/grpc.go b/grpc.go index 4015780..671f2c0 100644 --- a/grpc.go +++ b/grpc.go @@ -659,10 +659,12 @@ func (g *grpcServer) Register() error { registered := g.registered g.Unlock() - if !registered { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) - } + if registered { + return nil + } + + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Registry [%s] Registering node: %s", config.Registry.String(), node.Id) } // create registry options @@ -672,11 +674,6 @@ func (g *grpcServer) Register() error { return err } - // already registered? don't need to register subscribers - if registered { - return nil - } - g.Lock() defer g.Unlock() @@ -787,10 +784,10 @@ func (g *grpcServer) Start() error { g.RUnlock() return nil } - g.RUnlock() - config := g.Options() + g.RUnlock() + // micro: config.Transport.Listen(config.Address) var ts net.Listener @@ -822,10 +819,11 @@ func (g *grpcServer) Start() error { } g.Lock() g.opts.Address = ts.Addr().String() + subscribes := g.subscribers g.Unlock() // only connect if we're subscribed - if len(g.subscribers) > 0 { + if len(subscribes) > 0 { // connect to the broker if err := config.Broker.Connect(); err != nil { return err