-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Rate LimitingOcelot feature: Rate LimitingOcelot feature: Rate LimitingSpring'24Spring 2024 releaseSpring 2024 releasebugIdentified as a potential bugIdentified as a potential bughighHigh priorityHigh prioritymergedIssue has been merged to dev and is waiting for the next releaseIssue has been merged to dev and is waiting for the next release
Milestone
Description
Expected 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 the if (entry.HasValue)
block:
Ocelot/src/Ocelot/RateLimit/RateLimitCore.cs
Lines 31 to 39 in 0b247af
// 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
Metadata
Metadata
Assignees
Labels
Rate LimitingOcelot feature: Rate LimitingOcelot feature: Rate LimitingSpring'24Spring 2024 releaseSpring 2024 releasebugIdentified as a potential bugIdentified as a potential bughighHigh priorityHigh prioritymergedIssue has been merged to dev and is waiting for the next releaseIssue has been merged to dev and is waiting for the next release