Skip to content

Commit 0e39195

Browse files
lance6716ti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#47959
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 7eb094b commit 0e39195

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

br/pkg/pdutil/pd.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ func pdRequest(
141141
return nil, errors.Trace(err)
142142
}
143143
reqURL := fmt.Sprintf("%s/%s", u, prefix)
144+
<<<<<<< HEAD
144145
req, err := http.NewRequestWithContext(ctx, method, reqURL, body)
145146
if err != nil {
146147
return nil, errors.Trace(err)
@@ -151,6 +152,19 @@ func pdRequest(
151152
}
152153
count := 0
153154
for {
155+
=======
156+
var (
157+
req *http.Request
158+
resp *http.Response
159+
)
160+
count := 0
161+
for {
162+
req, err = http.NewRequestWithContext(ctx, method, reqURL, body)
163+
if err != nil {
164+
return 0, nil, errors.Trace(err)
165+
}
166+
resp, err = cli.Do(req) //nolint:bodyclose
167+
>>>>>>> b9b336843bc (lightning: every HTTP retry should use its own request (#47959))
154168
count++
155169
if count > pdRequestRetryTime || resp.StatusCode < 500 {
156170
break

br/pkg/pdutil/pd_serial_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package pdutil
44

55
import (
6+
"bytes"
67
"context"
78
"encoding/hex"
89
"encoding/json"
@@ -186,8 +187,16 @@ func TestPDRequestRetry(t *testing.T) {
186187
w.WriteHeader(http.StatusOK)
187188
}))
188189
cli := http.DefaultClient
190+
cli.Transport = http.DefaultTransport.(*http.Transport).Clone()
191+
// although the real code doesn't disable keep alive, we need to disable it
192+
// in test to avoid the connection being reused and #47930 can't appear. The
193+
// real code will only meet #47930 when go's internal http client just dropped
194+
// all idle connections.
195+
cli.Transport.(*http.Transport).DisableKeepAlives = true
196+
189197
taddr := ts.URL
190-
_, reqErr := pdRequest(ctx, taddr, "", cli, http.MethodGet, nil)
198+
body := bytes.NewBuffer([]byte("test"))
199+
_, reqErr := pdRequest(ctx, taddr, "", cli, http.MethodPost, body)
191200
require.NoError(t, reqErr)
192201
ts.Close()
193202
count = 0

0 commit comments

Comments
 (0)