diff --git a/pkg/utils/apiutil/serverapi/middleware.go b/pkg/utils/apiutil/serverapi/middleware.go index 18dd2f52155..ce3617453d2 100755 --- a/pkg/utils/apiutil/serverapi/middleware.go +++ b/pkg/utils/apiutil/serverapi/middleware.go @@ -264,7 +264,7 @@ func (h *redirector) waitForLeader(r *http.Request) (leader *pdpb.Member) { } case <-r.Context().Done(): return - case <-h.s.LoopContext().Done(): + case <-h.s.Context().Done(): return } } diff --git a/tests/server/api/api_test.go b/tests/server/api/api_test.go index f874e69aa1b..b32739b631e 100644 --- a/tests/server/api/api_test.go +++ b/tests/server/api/api_test.go @@ -611,9 +611,10 @@ func (suite *redirectorTestSuite) TestRedirect() { err := leader.ResignLeader() re.NoError(err) for _, svr := range suite.cluster.GetServers() { - url := fmt.Sprintf("%s/pd/api/v1/version", svr.GetServer().GetAddr()) + request, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s/pd/api/v1/version", svr.GetServer().GetAddr()), http.NoBody) + re.NoError(err) testutil.Eventually(re, func() bool { - resp, err := tests.TestDialClient.Get(url) + resp, err := dialClient.Do(request) re.NoError(err) defer resp.Body.Close() _, err = io.ReadAll(resp.Body)