diff --git a/br/pkg/pdutil/pd.go b/br/pkg/pdutil/pd.go index 05c320eab319f..851009e7aeeb0 100644 --- a/br/pkg/pdutil/pd.go +++ b/br/pkg/pdutil/pd.go @@ -164,10 +164,13 @@ func pdRequestWithCode( return 0, nil, errors.Trace(err) } reqURL := fmt.Sprintf("%s/%s", u, prefix) - var resp *http.Response + var ( + req *http.Request + resp *http.Response + ) count := 0 for { - req, err := http.NewRequestWithContext(ctx, method, reqURL, body) + req, err = http.NewRequestWithContext(ctx, method, reqURL, body) if err != nil { return 0, nil, errors.Trace(err) } diff --git a/br/pkg/pdutil/pd_serial_test.go b/br/pkg/pdutil/pd_serial_test.go index 0436c7e381497..329c34c9ed810 100644 --- a/br/pkg/pdutil/pd_serial_test.go +++ b/br/pkg/pdutil/pd_serial_test.go @@ -198,7 +198,6 @@ func TestPDRequestRetry(t *testing.T) { body := bytes.NewBuffer([]byte("test")) _, reqErr := pdRequest(ctx, taddr, "", cli, http.MethodPost, body) require.NoError(t, reqErr) - ts.Close() count = 0 ts = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -207,7 +206,6 @@ func TestPDRequestRetry(t *testing.T) { w.WriteHeader(http.StatusGatewayTimeout) return } - w.WriteHeader(http.StatusOK) })) taddr = ts.URL