Skip to content

Commit

Permalink
fix: duplicated start grpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 27, 2024
1 parent 8836206 commit 4830d5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
31 changes: 18 additions & 13 deletions core/grpc/client/client_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type GrpcClientV2 struct {
stream grpc2.NodeService_SubscribeClient
msgCh chan *grpc2.StreamMessage
err error
once sync.Once

// clients
NodeClient grpc2.NodeServiceClient
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion core/grpc/server/node_server_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4830d5d

Please sign in to comment.