Bugfix - Attempt Number Accuracy #12
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What Happened?
Ooof... this is gross.
There's a couple of issues here that have existed for 5+ years:
retry.Action
functions are sent an attempt number, but its been erroneously 0-based. Thestrategy.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 toretry.Action
has been off-by-one for all these years. 😞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 at1
and represent the actual attempt number of times that the action has been called, whilestrategy.Strategy
functions will continue to receive the pre-action attempt number starting at0
as usual. Thestrategy.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 usesstrategy.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.