Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RateLimitController aggressive timeout issue #716

Merged
merged 1 commit into from
Mar 10, 2022

Conversation

FrederikBolding
Copy link
Member

Description
Fix an issue with RateLimitController where we applied the timeout too aggressively

  • CHANGED:
    • Changed RateLimitController to only apply timeout once for each time window

Checklist

  • Tests are included if applicable
  • Any added code is fully documented

Comment on lines +172 to +180
const previous = (state as any).requests[api][origin] ?? 0;
(state as any).requests[api][origin] = previous + 1;

if (previous === 0) {
setTimeout(
() => this.resetRequestCount(api, origin),
this.rateLimitTimeout,
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the intended behavior is that the first request initiates a timeout, during which the requesting origin can make no more than rateLimitCount number of requests, then my late-night brain assesses that this is correct.

Previously, every request would initiate a new timeout, regardless of whether the previous one had expired, and that's definitely not correct.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly the conclusion that I came to as well, your described behaviour was the intention, but it may been altered throughout the implementation process without a good test to remind me. That should be corrected with this PR. Feel free to wait for tomorrow to do an actual review 😄

@FrederikBolding FrederikBolding marked this pull request as ready for review March 10, 2022 07:37
@FrederikBolding FrederikBolding requested a review from a team as a code owner March 10, 2022 07:37
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see how the previous behavior wasn't correct and this makes sense to me. Nice catch!

@FrederikBolding FrederikBolding merged commit 6ee6e41 into main Mar 10, 2022
@FrederikBolding FrederikBolding deleted the fb/fix-rate-limit-aggressive-timeout branch March 10, 2022 17:04
soralit pushed a commit to KeystoneHQ/controllers that referenced this pull request Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants