-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NewExponentialJitterBackoff calculates maxBackoffAttempts to a negative number #2227
Comments
Hi @minj131 , Thanks for opening this issue, this is obviously a bug: package main
import (
"fmt"
"github.com/aws/aws-sdk-go-v2/aws/retry"
"time"
)
func main() {
backoff := retry.NewExponentialJitterBackoff(100 * time.Millisecond)
fmt.Println("maxBackoffAttempts:", backoff)
}
// results in
// maxBackoffAttempts: -3.321928094887362 Im more curious about the use case; Why would you want a backoff that is less than 100ms? I'd probably throttle my requests in seconds range rather than milliseconds. Thanks, |
Your observation of the behavior is accurate but the value being calculated to < 0 doesn't really have a negative effect on the overall retry loop. In the strictest sense, the retry delay for a given attempt in seconds is supposed to be calculated like so:
Evidently we have previously applied this optimization of deriving the cutoff point where we reach the maximum to avoid some arithmetic. In doing so we've introduced a quirk in the specified behavior where we "stick" to the maximum once we've crossed that # of attempts. This deviates from the specification, since values of b could conceivably be small enough to sometimes result in t_i evaluating to something less than MAX_BACKOFF even at large values of i. A side effect of this is that any max backoff below Regardless I view this as a minor quirk and an established one, changing it now in this MV would have some effect on the cadence of retried calls and I find it hard to justify changing it at this point. |
|
Describe the bug
Passing any value less than 1 such as
retry.NewExponentialJitterBackoff(100 * time.Millisecond)
results in a negative number formaxBackoffAttempts
when usingNewExponentialJitterBackoff
Expected Behavior
The retryer should retry with jitter not the max backoff until the max backoff attempts is reached.
Current Behavior
Output logs
Reproduction Steps
I create a custom retryer like below
which returns the
ExponentialJitterBackoff
asAnd retries run this logic
However
math.Log2(float64(100 * time.Milisecond) / float64(time.Second))
evaluates to a negative number so thisalways evaluates to true. Every retry will wait for its maxBackoff.
Possible Solution
No response
Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
Compiler and Version used
go version go1.20.4 darwin/amd64
Operating System and version
macOS Ventura 13.4
The text was updated successfully, but these errors were encountered: