Skip to content
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

Infinite loop if ExponentialBackoff.Stop is zero/unset #133

Open
bradleyjkemp opened this issue May 24, 2023 · 4 comments
Open

Infinite loop if ExponentialBackoff.Stop is zero/unset #133

bradleyjkemp opened this issue May 24, 2023 · 4 comments

Comments

@bradleyjkemp
Copy link

If ExponentialBackoff.Stop is zero (e.g. if you forget to initialise it) then the backoff function can run into an infinite loop on this line:

if next = b.NextBackOff(); next == Stop {

Here b.NextBackoff() returns the ExponentialBackoff.Stop value but it's being compared against the package constant Stop (defined as -1)

I'm not sure why you'd ever want to change this value (so perhaps it shouldn't have been an exported member?) but I think this needs changing to either:

  • Compare b.NextBackoff() against whatever ExponentialBackoff.Stop is set to
  • Do some initialising logic so that ExponentialBackoff.Stop is always set to a sensible value
@Dean-Coakley
Copy link

It's a shame that it's exported.

As far as I know usage of NewExponentialBackOff will ensure that ExponentialBackoff.Stop is always set to a sensible value as you want. So I'm not sure there is anything to be done here.

@bradleyjkemp
Copy link
Author

Oh yeah entirely my mistake for initialising the struct myself rather than using the constructor. Would be nice to guard against this though, as the effects are pretty bad! (rather than running the function with a graceful backoff, run it repeatedly with no delay 😬)

@Dean-Coakley
Copy link

Well un-exporting the field would be a breaking change and won't be done in v4 anyway, and unfortunately as far as I know a v5 is not planned. 😕

@tot-ra
Copy link

tot-ra commented Jul 6, 2023

Encountered same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants