-
Notifications
You must be signed in to change notification settings - Fork 194
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
BUG (1.7.34) possible endless loop if Burst rate is reached: WaitForPermittedRequest - "RequestsUsed >= Burst" replenish token (RateLimit.cs) #815
Comments
@FinnReilly We need urgent recheck on this |
@abuzuhri have submitted a PR - have included tests to demonstrate that the fixed code works as intended |
Hi, I was wondering why my production Order API has been running at over 90% CPU usage for days and stopped executing threads entirely. I’ve been trying to track down the issue for several days and finally found the root cause. The problem seems to be related to extreme memory allocation in the Small Object Heap, caused predominantly by Here is an example from our diagnostics (rider):
This behavior only occurs with version 1.7.34. With version 1.7.33, this problem does not happen. Based on the stack trace, it seems related to the rate-limiting logic and might also align with the potential endless loop described in this ticket. This is a critical issue for us, as it completely destabilizes our system. Please let me know if additional details are needed or if there’s any recommended workaround for now. |
@FinnReilly I really hope we can do rollback for that change soon and later we can take deep look on this |
Hello,
first of all, happy new year.
thank you very much for this project and also the other supporters!
maybe it's already in the previous version. everything was ok in 1.7.27.
maybe case is same issue: #812 GetItemOffersBatch seems to be broken with the 1.7.34 update
for example:
getOrder has Burst rate of "20".
if 20 is reached: "WaitForPermittedRequest" - "while (RequestsUsed >= Burst)" in combination with else "//replenish token IncrementAvailableTokens(debugMode)" => endless loop
*** documented in the code below
maybe issue is in "IncrementAvailableTokens(debugMode)"
Can anybody fix it?
Thanks,
Marco
RateLimit.cs
WaitForPermittedRequest
public async Task WaitForPermittedRequest(CancellationToken cancellationToken = default, bool debugMode = true)
{
if (RequestsUsed < 0)
{
RequestsUsed = 0;
}
int ratePeriodMs = GetRatePeriodMs();
var requestsUsedAtOnset = RequestsUsed;
// when requests used more than zero, replenish according to time elapsed
IncrementAvailableTokens(debugMode);
var nextRequestsSent = RequestsUsed + 1;
var nextRequestsSentTxt = (nextRequestsSent > Burst) ? "FULL" : nextRequestsSent.ToString();
WriteDebug($"[RateLimits ,{this.RateLimitType,15}]: {DateTime.UtcNow.ToString(),10}\t Request/Burst: {nextRequestsSentTxt}/{Burst}\t Rate: {Rate}/{ratePeriodMs}ms", debugMode);
var requestIsPermitted = false;
while (!requestIsPermitted)
{
// if bucket is currently empty, enter wait loop for replenishment
while (RequestsUsed >= Burst)
{
***!!! endless loop if RequestsUsed is >=20 !!!!
}
}
IncrementAvailableTokens(bool isDebug)
// increments available tokens, unless another thread has already incremented them.
private void IncrementAvailableTokens(bool isDebug)
{
WriteDebug($"Attempting to increment tokens", isDebug);
lock (_locker)
{
var ratePeriodMilliseconds = GetRatePeriodMs();
var requestsToReplenish = ratePeriodMilliseconds == 0 ? 0 : (DateTime.UtcNow - LastRequestReplenished).Milliseconds / ratePeriodMilliseconds;
WriteDebug($"{requestsToReplenish} tokens to replenish since {LastRequestReplenished}", isDebug);
if (requestsToReplenish == 0 || RequestsUsed == 0)
{
return;
}
The text was updated successfully, but these errors were encountered: