Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[RateLimiter] FixRateLimit->getRetryAfter() return value when consuming0 or last tokens.#52835
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
carsonbot commentedNov 30, 2023
Hey! I see that this is your first PR. That is great! Welcome! Symfony has acontribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
derrabus commentedNov 30, 2023
Thank you for your contribution. Please not that we don't merge any changes without a test that covers it. |
ERuban commentedNov 30, 2023
Hey@derrabus, |
derrabus commentedNov 30, 2023
Well, you're changing |
bfecd20 toa2a89d7CompareERuban commentedNov 30, 2023
@derrabus, done |
src/Symfony/Component/RateLimiter/Tests/Policy/SlidingWindowLimiterTest.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
derrabus commentedNov 30, 2023
@wouterj Can you have a look at this? Consuming a rate limiter without actually consuming anything feels like a hack. Is this a scenario we support? I understand that it simply has somehow worked previously. |
ERuban commentedNov 30, 2023
Yeah, otherwise we need some another way to get current RateLimit. |
ERuban commentedNov 30, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
And, yes, using it before I got the wrong time to retry, it was the time when all tokens will be available, not the first one. With that fix I got the time for the next available token now. |
RobertMe commentedNov 30, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This is used in the framework itself too: symfony/src/Symfony/Component/HttpFoundation/RateLimiter/AbstractRequestRateLimiter.php Lines 32 to 46 in8cd61c5
This allows checking whether a token can be consumed. In this case it's used in the LoginThrottlingListener which checks if a token is available in theCheckPassportEvent listener, if there are none available (as indicated bypeek /consume(0)) the login will be denied. If it's allowed (still consumable) it will only be actually consumed when the login fails. That's at least one use case where "peeking" / "consume-ing without actually consuming" is used. |
ERuban commentedNov 30, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Nice example, thank you. So then, what about to implement smth like I can try to do it then or update that PR. what do you think? |
RobertMe commentedNov 30, 2023
That would be a BC break (you can't change the interface). And doing it in a backwards compatible manner would probably mean it becomes a feature, not a bugfix, so would end up in 7.1 earliest. |
ERuban commentedNov 30, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
We're anyway have a BC break here (for
Hm, is it a BC break if we will add some new into the interface w/o changing the existing methods? Not sure. |
ERuban commentedDec 5, 2023
derrabus commentedDec 5, 2023
I only did an initial triage on this PR. I've mentioned@wouterj because I believe he can conduct a better review on this topic than I could. However, it's SymfonyCon this week, so he's probably busy. |
ERuban commentedDec 6, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Have found that Have updated the PR. |
RateLimit->getRetryAfter() return value when consuming0 or last tokens.ERuban commentedDec 13, 2023
@wouterj done.
|
4691618 toc15d76dCompareKocal commentedDec 18, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This comment was marked as off-topic.
This comment was marked as off-topic.
wouterj commentedDec 28, 2023
Sorry for causing confusion here, I might have tested a bit wrongly. In any case, I've created a PR for 6.3 to make the behavior across all policies consistent and make sure it's covered by a test:#53259 When that is merged, we can rebase this PR and fix the remaining issues caused by the reservation feature in 6.4. As a little side note, please do not ping maintainers if nothing changed. We're all doing this completely voluntary, so there is no guarantee whatsoever that we're responding within a certain time frame. |
…licies (wouterj)This PR was merged into the 6.3 branch.Discussion----------[RateLimit] Test and fix peeking behavior on rate limit policies| Q | A| ------------- | ---| Branch? | 6.3| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues | Ref#52835| License | MITAlthough heavily discouraged for user-land code, we've implemented peeking behavior for rate limiting in 6.2 with#46110. However, I found that our rate limit policies show very inconsistent behavior on this.As we didn't have great test covering peeking return values, we broke BC with#51676 in 6.4. I propose this PR to verify the behavior of the policies and also make it inconsistent. I target 6.3 because we rely on this in the login throttling since 6.2 and this shows buggy error messages ("try again in 0 minute") when not using the default policy for login throttling.> [!NOTE]> When merging this PR, there will be heavy merge conflicts in the SlidingWindowLimiter. You can ignore the changes in this PR for this policy in 6.4. I'll rebase and update#52835 to fix the sliding window limiter in 6.4+Commits-------e4a8c33 [RateLimit] Test and fix peeking behavior on rate limit policies
nicolas-grekas commentedDec 29, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
wouterj commentedDec 29, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi! I've rebased the branch of this PR and reintroduced the testcase added by my PR in 6.3. I've also reorganized your code a bit, to reduce the number of if-else statements (I always struggle reading rate limiter code, so I like to keep things as simple as possible even if this comes with a cost of some code duplication). However, GitHub for some reason doesn't allow me to push to this PR (even though the UI states maintainers should be allowed). So I've started a new PR:#53282 |
ERuban commentedDec 29, 2023
@wouterj huh, just one more approved but closed PR, ok. Last one was heresymfony/symfony-docs#19205 |
wouterj commentedDec 29, 2023
ERuban commentedDec 29, 2023
@wouterj ok, done |
wouterj commentedDec 29, 2023
I'm sorry, it still doesn't seem to work: I haven't had this before, so not sure how to help you resolve this in the future. In any case, keeping your commit is the most important bit of information :) |
ERuban commentedDec 29, 2023
ok, nevermind. just let it work at the end) |
ERuban commentedDec 29, 2023
also, |
ERuban commentedDec 30, 2023
It was my last PR to Symfony. (It is a bit weird to be approved but not merged more than one time) Thanks to all, nice work. |
nicolas-grekas commentedDec 30, 2023
…when consuming 0 or last tokens (wouterj, ERuban)This PR was merged into the 6.4 branch.Discussion----------[RateLimiter] Fix RateLimit->getRetryAfter() return value when consuming 0 or last tokens| Q | A| ------------- | ---| Branch? | 6.4| Bug fix? | yes| New feature? | no| Deprecations? | no| Issues | -| License | MITReplaces#52835 Original description:> Have got some BC after updating the project to Symfony 6.4 (after that PR#51676).>> Sometimes I need to get `RateLimit` object without consuming just before consuming a try, in example:> ```php> $rateLimit = $limiter->consume(0);> if ($rateLimit->getRemainingTokens() === 0) {> throw new SomeException($rateLimit->getRetryAfter());> }> ...> $limiter->consume(1)> ...> ```> and found that in that case `$rateLimit->getRetryAfter()` always returns `now`.>> So this PR fixes it.Commits-------677b8b7 [RateLimit] Allow to get RateLimit without consuming again169e383 Reintroduce peek consume test for sliding window policy
ERuban commentedJan 25, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@nicolas-grekas#53282 (comment) Also there a second PR that waiting for you@wouterj a very long time...#53064 |
wouterj commentedJan 25, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sorry, I can't recall having any agreement with the Symfony organization or community about my response time. Been enjoying new years, some busy work weeks and a winter holiday, knowing that the BC break in 6.4 is fixed (which this PR was about). |
ERuban commentedJan 25, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@wouterj sorry for that, but it was your initiative here at the end of the comment#52835 (comment) |



Uh oh!
There was an error while loading.Please reload this page.
Have got some BC after updating the project to Symfony 6.4 (after that PR#51676).
Sometimes I need to get
RateLimitobject without consuming just before consuming a try, in example:and found that in that case
$rateLimit->getRetryAfter()always returnsnow.So this PR fixes it.
UPDATE
Have found that
RateLimit->getRetryAfter()returnsnowwhen the last token was consumed forsliding_windowandfixed_window. So fixed it too.