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

Rate-limiter counts the same request more than once when there are multiple rate-limiter rules #40

Closed
rbracco opened this issue Oct 3, 2023 · 1 comment

Comments

@rbracco
Copy link

rbracco commented Oct 3, 2023

@router.get("/", dependencies=[
    Depends(RateLimiter(times=20, seconds=60)),  # 1 minute
    Depends(RateLimiter(times=200, seconds=10 * 60)),  # 10 minutes
    Depends(RateLimiter(times=1200, seconds=60 * 60)),  # hourly limit
    Depends(RateLimiter(times=5000, seconds=24 * 60 * 60)),  # daily limit)]

My route is only being hit once but each request is being counted as 4 requests by the rate limiter, thus the limit for 1 minute is hit after only 5 requests instead of 20. If I comment out 2 of the rules, it hits the limit after 10 requests. I believe there is a bug leading to each request being counted N times when you have N rules.

My current workaround is to just change the code to...

@router.get("/", dependencies=[
    Depends(RateLimiter(times=4*20, seconds=60)),  # 1 minute
    Depends(RateLimiter(times=4*200, seconds=10 * 60)),  # 10 minutes
    Depends(RateLimiter(times=4*1200, seconds=60 * 60)),  # hourly limit
    Depends(RateLimiter(times=4*5000, seconds=24 * 60 * 60)),  # daily limit)]
@rbracco
Copy link
Author

rbracco commented Oct 6, 2023

Closing as this was a side-effect of #41

@rbracco rbracco closed this as completed Oct 6, 2023
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

No branches or pull requests

1 participant