Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[RateLimiter] fix incorrect retryAfter of FixedWindow#49070

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

Merged
fabpot merged 1 commit intosymfony:5.4fromRobertMe:fixed-window-retry-after
Jul 13, 2023

Conversation

@RobertMe
Copy link
Contributor

QA
Branch?5.4
Bug fix?yes
New feature?no
Deprecations?no
Tickets
LicenseMIT
Doc PR

A FixedWindow always endsintervalInSeconds after the start time (timer). So when calculating the time to consume some tokens the tokens will always be available attimer + intervalInSeconds. But currently this is reported incorrectly ascalculateTimeForTokens() calculates the time based on the desired amount of tokens (and cycles) while it doesn't take into accountmaxSize amount of tokens become available at the windows end.

Furthermore calculating the amount of needed cycles is incorrect. This as all tokens become available at once (at the windows end) and you can't consume more tokens thanmaxSize (which is validated at the start ofFixedWindowLimiter::reserve, in case oftokens > limit it throws).

Note: I don't think that changing the signature ofcalculateTimeForTokens is a deprecation. This as theWindow class is marked as@internal. So it should only be used by theRateLimiter component.

@RobertMe
Copy link
ContributorAuthor

I'm uncertain about the Psalm failure.return ceil(...) results in afloat (while it is an integer value), and the return type is declared asint. But the old code also was based onceil() resulting in afloat return value, while the return type was declared asint. So I guess that's fine?

@Robert-Embloom
Copy link
Contributor

@wouterj it seems like you're the original developer of the RateLimiter component. So may I ask you to have a look at this? (as it seems to have gone unnoticed in general)

@RobertMeRobertMeforce-pushed thefixed-window-retry-after branch fromc612584 to5c380e9CompareJuly 10, 2023 10:31
A FixedWindow always ends `intervalInSeconds` after the start time(`timer`). So when calculating the time to consume some tokens thetokens will always be available at `timer + intervalInSeconds`. Butcurrently this is reported incorrectly as `calculateTimeForTokens()`calculates the time based on the desired amount of tokens (and cycles)while it doesn't take into account `maxSize` amount of tokens becomeavailable at the windows end.Furthermore calculating the amount of needed cycles is incorrect. Thisas all tokens become available at once (at the windows end) and youcan't consume more tokens than `maxSize` (which is validated at thestart of `FixedWindowLimiter::reserve`, in case of `tokens > limit` itthrows).
@RobertMeRobertMeforce-pushed thefixed-window-retry-after branch from5c380e9 to2316932CompareJuly 10, 2023 11:11
@fabpot
Copy link
Member

Thank you@RobertMe.

Robert-Embloom reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@fabpotfabpotfabpot approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

5 participants

@RobertMe@Robert-Embloom@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp