Skip to content

Conversation

Rican7
Copy link
Owner

@Rican7 Rican7 commented Aug 1, 2021

What Happened?

Ooof... this is gross.

There's a couple of issues here that have existed for 5+ years:

  1. The retry.Action functions are sent an attempt number, but its been erroneously 0-based. The strategy.Strategy also receives an attempt number, but that's supposed to be 0-based, as its supposed to allow for pre-run-logic. Sooo, yea, the attempt number sent to retry.Action has been off-by-one for all these years. 😞
  2. The strategy.Limit function has also had an off-by-one error for all these years... as the strategies are again supposed to be 0-based. Worse even, is that it used to be correct, and then somewhere along the line I thought I "fixed" it with commit 678601c. Damn. 😢

The Fix

In any case, this PR fixes these errors!

The retry.Action attempt number will now always start at 1 and represent the actual attempt number of times that the action has been called, while strategy.Strategy functions will continue to receive the pre-action attempt number starting at 0 as usual. The strategy.Limit function has been fixed and tests have been expanded/improved to prevent this from happening again in the future. 🤞

Impact

Yea, so this will definitely break backwards-compatibility. Existing retry.Action implementations will have to adapt to the new attempt number being +1 compared to before, and existing code that uses strategy.Limit will have to expect that it'll there will be one fewer attempt than before (it was wrong before and giving one too many).

I'll be tagging a release once this is merged.

Rican7 added 5 commits July 31, 2021 19:38
It'll still start at 0 for strategies.
Just now realizing that the limit strategy has had an off-by-one error
for 5+ years now...

Not sure what I was thinking here:
678601c
(It's had an off-by-one error for 5+ years now...)

déjà vu: 678601c
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 90c002c on bugfix/attempt-number-accuracy into ee26000 on master.

@Rican7 Rican7 merged commit bef6c43 into master Aug 1, 2021
@Rican7 Rican7 deleted the bugfix/attempt-number-accuracy branch August 1, 2021 02:42
@emtammaru
Copy link

Maybe it would be better to create a v1 release with this change since it is breaking?

@Rican7
Copy link
Owner Author

Rican7 commented Nov 4, 2021

Maybe it would be better to create a v1 release with this change since it is breaking?

That's not necessary, thanks to the v0 major version right now: https://golang.org/doc/modules/version-numbers#v0-number

@emtammaru
Copy link

It might not be strictly necessary, but it would be nice considering the gross nature of this change ;) I hear you though. In all seriousness, thanks for making this package. I've been using it a lot, and it works well. What other changes do you have planned before making an official v1 release?

@Rican7
Copy link
Owner Author

Rican7 commented Nov 4, 2021

It might not be strictly necessary, but it would be nice considering the gross nature of this change ;) I hear you though.

At this point, this has been released for over 3 months, so that ship has kind of sailed. I'll keep it in mind for the future, though. I appreciate the feedback. 😃

In all seriousness, thanks for making this package. I've been using it a lot, and it works well.

I appreciate it! Thank you! 😊

What other changes do you have planned before making an official v1 release?

I've been trying to come up with a way to integrate context.Context without really making the API gross or redundant everywhere. I'm hoping some developments with generics will allow for a cleaner API there, but I'm not sure. This package is in use by quite a lot of people and is even in some relatively high-profile projects/codebases, so I want to make sure I do this right but I also don't feel compelled to get this to v1 within any time frame.

Its been a very stable package and has received very few changes in over 5 years, so I'm in no rush. 🙂

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

Successfully merging this pull request may close these issues.

3 participants