Rate Limiting works incorrectly if PeriodTimespan value is greater than Period
See original GitHub issueExpected Behavior
Rate Limiting works as documented for such parameter values: Period: 1 second PeriodTimeSpan: 30 seconds Limit: 100
Scenario: Request flow, 10-20 requests per sec, should be allowed.
Status: not equal to 429
Actual Behavior / Motivation for New Feature
With the same parameter values from Expected Behavior Ocelot returns status 429 aka “Rate limit exceeded”. It seems this issue caused by code in RateLimitCore.cs lines 35-43
// entry has not expired
if (entry.Value.Timestamp + TimeSpan.FromSeconds(rule.PeriodTimespan) >= DateTime.UtcNow)
{
// increment request count
var totalRequests = entry.Value.TotalRequests + 1;
// deep copy
counter = new RateLimitCounter(entry.Value.Timestamp, totalRequests);
}
Ocelot increments request counter if request has been received in interval [FirstRequestTime : FirstRequestTime + PeriodTimeSpan] According to the documentation counter should be incremented if request is in interval [FirstRequestTime : FirstRequestTime + Period].
Steps to Reproduce the Problem
- Set Rate Limiting configuration parameters:
- Period: 1 second
- PeriodTimeSpan: 30 seconds
- Limit: 100
- Generate a consequent request flow (10-20 requests per second) for more than 12 seconds
- Ensure Ocelot returns status 429
Specifications
- Ocelot Version: Latest, 19.0.2
- Feature: Rate Limiting
Issue Analytics
- State:
- Created a year ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Questions for Rate Limiting · Issue #910 · ThreeMammals ...
After the PeriodTimespan, request will works again, but in a Period(1min here), the count of successful requests is more than the limit(5 ...
Read more >Exploring Communication of Rate Limits in ASP.NET Core ...
This post explores rate limit headers proposed in current Internet-Draft and how those can be served and consumed in .NET.
Read more >Yii2 RateLimiter header X-Rate-Limit-Reset has wrong value
So, if the rate limit is 100 and the time period/window is 3600 seconds, then I understand it should work like this:.
Read more >Rate Limiting — Ocelot 1.0.0 documentation
Period - This value specifies the period that the limit applies to, such as 1s, 5m, 1h,1d and so on. If you make...
Read more >Pipe-Viewer problem with changing Rate-Limit
Because of the write limitation, this only causes an issue when you set the rate limit to a value greater than the write...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think yes. But give me a little time, please, to dive into the context. Also I apologize for inacurate title.
@sergio-str Sergii
I would like your checking this bug for the latest build/version which is 19.0.2 and .NET 7. Your reported Specifications info with “Ocelot Version: 18” is quite outdated. Please, use the latest package and/or just use top commits from develop branch version!
Do not you mind if I change Ocelot Version to 19.0.2 in Specifications paragraph? That’s how I and team can accept this bug after our common validation. And the team will not accept bugs for old versions, because of outdating.