-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Have
DefaultClientRetryPolicy
account for degenerately high attempt…
… counts (#698) This one's here to address #697, where's it been reported that it may be possible for retry schedules to overflow to the past when reaching degenerately high numbers of attempts. I couldn't reproduce the reported problem, but it is possible for `time.Duration` to overflow, so here we shore up `DefaultClientRetryPolicy` so that we're explicitly defining what behavior should occur under these conditions. The maximum length of time that can go in a `time.Duration` is about 292 years. Here's a sample program that demonstrates an overflow happening: func main() { const maxDuration time.Duration = 1<<63 - 1 var maxDurationSeconds = float64(maxDuration / time.Second) notOverflowed := time.Duration(maxDurationSeconds) * time.Second fmt.Printf("not overflowed: %+v\n", notOverflowed) overflowed := time.Duration(maxDurationSeconds+1) * time.Second fmt.Printf("overflowed: %+v\n", overflowed) } not overflowed: 2562047h47m16s overflowed: -2562047h47m16.709551616s Here, modify `DefaultClientRetryPolicy` so that if it were to return a next retry duration greater than what would fit in `time.Duration`, we just return 292 years instead. The maximum bound occurs at 310 retries, so every retry after 310 increments by 292 years. I didn't bother putting a maximum bound on the time returned by `NextRetry` because the maximum `time.Time` in Go is somewhere in the year 219250468, so even in 292 year increments, you'll never get there.
- Loading branch information
Showing
4 changed files
with
157 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters