Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants