Skip to content

Commit

Permalink
*: fix member race problem (#6070)
Browse files Browse the repository at this point in the history
ref #5310, ref #6069

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
rleungx and ti-chi-bot authored Mar 6, 2023
1 parent c40e319 commit 312e5b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 11 additions & 1 deletion server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,17 @@ func (s *GrpcServer) wrapErrorToHeader(errorType pdpb.ErrorType, message string)
func (s *GrpcServer) GetMembers(context.Context, *pdpb.GetMembersRequest) (*pdpb.GetMembersResponse, error) {
// Here we purposely do not check the cluster ID because the client does not know the correct cluster ID
// at startup and needs to get the cluster ID with the first request (i.e. GetMembers).
members, err := s.Server.GetMembers()
if s.IsClosed() {
return &pdpb.GetMembersResponse{
Header: &pdpb.ResponseHeader{
Error: &pdpb.Error{
Type: pdpb.ErrorType_UNKNOWN,
Message: errs.ErrServerNotStarted.FastGenByArgs().Error(),
},
},
}, nil
}
members, err := cluster.GetMembers(s.GetClient())
if err != nil {
return &pdpb.GetMembersResponse{
Header: s.wrapErrorToHeader(pdpb.ErrorType_UNKNOWN, err.Error()),
Expand Down
3 changes: 1 addition & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,7 @@ func (s *Server) GetMembers() ([]*pdpb.Member, error) {
if s.IsClosed() {
return nil, errs.ErrServerNotStarted.FastGenByArgs()
}
members, err := cluster.GetMembers(s.GetClient())
return members, err
return cluster.GetMembers(s.GetClient())
}

// GetServiceMiddlewareConfig gets the service middleware config information.
Expand Down

0 comments on commit 312e5b4

Please sign in to comment.