From ab97b9a267f3a733b587fc96a1af90e39767331d Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 12 Dec 2023 14:16:47 +0800 Subject: [PATCH] mcs: fix panic of GetMinTS (#7529) close tikv/pd#7528 Signed-off-by: Ryan Leung Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com> --- server/grpc_service.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/grpc_service.go b/server/grpc_service.go index 6acc13b8187..fa74f1ea8b6 100644 --- a/server/grpc_service.go +++ b/server/grpc_service.go @@ -328,11 +328,11 @@ func (s *GrpcServer) GetMinTSFromTSOService(dcLocation string) (*pdpb.Timestamp, // Get the minimal timestamp from the TSO servers/pods var mutex syncutil.Mutex - resps := make([]*tsopb.GetMinTSResponse, len(addrs)) + resps := make([]*tsopb.GetMinTSResponse, 0) wg := sync.WaitGroup{} wg.Add(len(addrs)) - for idx, addr := range addrs { - go func(idx int, addr string) { + for _, addr := range addrs { + go func(addr string) { defer wg.Done() resp, err := s.getMinTSFromSingleServer(s.ctx, dcLocation, addr) if err != nil || resp == nil { @@ -342,8 +342,8 @@ func (s *GrpcServer) GetMinTSFromTSOService(dcLocation string) (*pdpb.Timestamp, } mutex.Lock() defer mutex.Unlock() - resps[idx] = resp - }(idx, addr) + resps = append(resps, resp) + }(addr) } wg.Wait()