question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rate Limiting works incorrectly if PeriodTimespan value is greater than Period

See original GitHub issue

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 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

  1. Set Rate Limiting configuration parameters:
  • Period: 1 second
  • PeriodTimeSpan: 30 seconds
  • Limit: 100
  1. Generate a consequent request flow (10-20 requests per second) for more than 12 seconds
  2. Ensure Ocelot returns status 429

Specifications

  • Ocelot Version: Latest, 19.0.2
  • Feature: Rate Limiting

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
sergio-strcommented, May 11, 2023

I think yes. But give me a little time, please, to dive into the context. Also I apologize for inacurate title.

0reactions
raman-mcommented, Jun 1, 2023

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found