-
Notifications
You must be signed in to change notification settings - Fork 29
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
Exponential and Fibonacci backoffs easily overflow #12
Comments
If you can figure out a way to do that such that it's still safe for concurrent use and doesn't introduce races, I'd be very interested :) |
Oooh, you want concurrency too. Should be feasible with a lock, or are those off limits? |
All the backoffs are safe for concurrent use and need to remain that way. They currently use atomic operations and are incredibly fast. When I benchmarked it, introducing a mutex added a fairly large performance hit. |
Percentage-wise I'm sure that's true, but you'd have to run a really tight retry loop for that to have any significance. I'm not sure what other options there are. It's not entirely easy to make WithCappedDuration to detect overflows (except for the special case of negative durations), and then we're down to adjusting the documentation to be clearer. Right now it's easy to read it as "just use WithCappedDuration and you'll be fine". |
I think |
Yes, but |
The problem is that |
Thanks for fixing this! |
This issue has been automatically locked since there has not been any |
If you let exponential or Fibonacci backoffs run for a while you'll easily get into an overflow situation. See https://go.dev/play/p/FUNKkZU0Kyn for an example. The NewExponential documentation says
but AFAICT you can't prevent overflows with WithCappedDuration since by then the overflow has already happened. How about changing said backoff functions to detect overflows and consistently return the largest time.Duration when the ceiling has been reached? Or am I missing something?
The text was updated successfully, but these errors were encountered: