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