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>
  • Loading branch information
JmPotato committed Jan 25, 2024
1 parent b94e74e commit 1da8d9d
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 1da8d9d

Please sign in to comment.