From cbc1692de752e47df3e48af1d0b34d7a927dce94 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Mon, 23 Sep 2024 10:48:06 +0800 Subject: [PATCH] mcs: fix potential data race in scheduling server (#8539) (#8641) close tikv/pd#8538 Signed-off-by: lhy1024 Co-authored-by: lhy1024 --- pkg/mcs/scheduling/server/server.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/mcs/scheduling/server/server.go b/pkg/mcs/scheduling/server/server.go index 07d6bbe3a33..ea52d2984f2 100644 --- a/pkg/mcs/scheduling/server/server.go +++ b/pkg/mcs/scheduling/server/server.go @@ -51,6 +51,7 @@ import ( "github.com/tikv/pd/pkg/storage/endpoint" "github.com/tikv/pd/pkg/storage/kv" "github.com/tikv/pd/pkg/utils/apiutil" + "github.com/tikv/pd/pkg/utils/etcdutil" "github.com/tikv/pd/pkg/utils/grpcutil" "github.com/tikv/pd/pkg/utils/logutil" "github.com/tikv/pd/pkg/utils/memberutil" @@ -184,7 +185,7 @@ func (s *Server) updateAPIServerMemberLoop() { if !s.IsServing() { continue } - members, err := s.GetClient().MemberList(ctx) + members, err := etcdutil.ListEtcdMembers(ctx, s.GetClient()) if err != nil { log.Warn("failed to list members", errs.ZapError(err)) continue @@ -199,6 +200,11 @@ func (s *Server) updateAPIServerMemberLoop() { cc, err := s.GetDelegateClient(ctx, s.GetTLSConfig(), ep.ClientURLs[0]) if err != nil { log.Info("failed to get delegate client", errs.ZapError(err)) + continue + } + if !s.IsServing() { + // double check + break } if s.cluster.SwitchAPIServerLeader(pdpb.NewPDClient(cc)) { if status.Leader != curLeader {