diff --git a/core/grpc/client/client_v2.go b/core/grpc/client/client_v2.go index 1e49733f5..a5f32ee0b 100644 --- a/core/grpc/client/client_v2.go +++ b/core/grpc/client/client_v2.go @@ -36,6 +36,7 @@ type GrpcClientV2 struct { stream grpc2.NodeService_SubscribeClient msgCh chan *grpc2.StreamMessage err error + once sync.Once // clients NodeClient grpc2.NodeServiceClient @@ -46,23 +47,27 @@ type GrpcClientV2 struct { } func (c *GrpcClientV2) Start() (err error) { - // connect - if err := c.connect(); err != nil { - return err - } + c.once.Do(func() { + // connect + err = c.connect() + if err != nil { + return + } - // register rpc services - c.Register() + // register rpc services + c.Register() - // subscribe - if err := c.subscribe(); err != nil { - return err - } + // subscribe + err = c.subscribe() + if err != nil { + return + } - // handle stream message - go c.handleStreamMessage() + // handle stream message + go c.handleStreamMessage() + }) - return nil + return err } func (c *GrpcClientV2) Stop() (err error) { diff --git a/core/grpc/server/node_server_v2.go b/core/grpc/server/node_server_v2.go index 6c69b14bc..051198ff4 100644 --- a/core/grpc/server/node_server_v2.go +++ b/core/grpc/server/node_server_v2.go @@ -69,7 +69,7 @@ func (svr NodeServerV2) Register(ctx context.Context, req *grpc.Request) (res *g if err != nil { return HandleError(err) } - log.Infof("[NodeServerV2] updated worker[%s] in db. id: %s", nodeKey, node.Id.Hex()) + log.Infof("[NodeServerV2] updated worker[%s] in db. id: %s", nodeKey, nodeDb.Id.Hex()) } } else if errors2.Is(err, mongo.ErrNoDocuments) { // register new