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.
There are 3x simultaneous bugs in the current RateLimiter. They currently cancel each other out so as whole the class is working - but individually none of the functions work as intended:
tooManyAttempts()
Currently if you have
5
attempts in the cache, and a$maxAttempts
of5
- this function returnsfalse
, when it should betrue
.The reason this was not noticed until now is:
hit()
Sets the initial count to
1
, then immediately increments it to2
. So the number of attempts is actually artificially increased by one.The reason that might never have been noticed until now is:
retriesLeft()
Currently the function does this:
Which you can see is actually artificially inflating the retriesLeft by 1. The reason is because, if you had the initial
hit()
wrong - the retriesLeft was also wrong. This PR reduces that code to justBecause you dont need to adjust
$attempts
anymore - you can take it "as is".This PR fixes all 3 bugs, yet should preserve the current behavior.
I've added an additional test for
retiresLeft()
to help prevent regressions.