Skip to content

Commit

Permalink
http/client, retry: copy a new Backoffer for each request (tikv#7684)
Browse files Browse the repository at this point in the history
ref tikv#7300

Copy a new `Backoffer` for each request to prevent race.

Signed-off-by: JmPotato <ghzpotato@gmail.com>
Signed-off-by: pingandb <songge102@pingan.com.cn>
  • Loading branch information
JmPotato authored and pingandb committed Jan 18, 2024
1 parent d3acab5 commit 503a22c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions client/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ func (ci *clientInner) requestWithRetry(
if reqInfo.bo == nil {
return execFunc()
}
// Copy a new backoffer for each request.
bo := *reqInfo.bo
// Backoffer also needs to check the status code to determine whether to retry.
reqInfo.bo.SetRetryableChecker(func(err error) bool {
bo.SetRetryableChecker(func(err error) bool {
return err != nil && !noNeedRetry(statusCode)
})
return reqInfo.bo.Exec(ctx, execFunc)
return bo.Exec(ctx, execFunc)
}

func noNeedRetry(statusCode int) bool {
Expand Down

0 comments on commit 503a22c

Please sign in to comment.