-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Description
Laravel Version
11.44.1
PHP Version
8.3.14
Database Driver & Version
Redis 7.4.1 on Laravel Forge
Description
I'm using the RateLimiter facade (via the Redis cache driver) to throttle remote API requests to 2000 per minute. This has worked perfectly for months.
Today, I noticed that the RateLimiter has, for the last 24 hours, stopped resetting after its 60 second decay time. This means that the 2000 slots have gradually been exhausted until no more slots were available, and the requests therefore rejected. There have been no code changes in recent days.
I have fixed this for now by clearing the RateLimiter via Tinker, and things seem to be working as normal again. But this is concerning, as I have no idea why the RateLimiter suddenly stopped working.
I note that other users seem to have a similar problem.
Here's the relevant code:
// Get the remaining rate limit capacity, with a max of 2000
$rateLimitRemaining = RateLimiter::remaining(key: $rateLimiterkey, maxAttempts: 2000);
// Get the page count for this chunk
$pageChunkCount = $pageChunk->count();
// Log the remaining rate limit
Log::info("There are {$pageChunkCount} pages in this chunk and {$rateLimitRemaining} slots available in the rate limiter.");
// Check rate limit capacity before processing each chunk
if ($rateLimitRemaining < $pageChunkCount) {
$secondsUntilAvailable = RateLimiter::availableIn(key: $rateLimiterkey);
Log::info("Rate limit reached. Releasing job to retry in {$secondsUntilAvailable} seconds. Processed {$processedChunks} chunks so far.");
$this->release($secondsUntilAvailable + 1);
return;
}
// Add the page count to the RateLimiter counter
RateLimiter::increment(key: $rateLimiterkey, decaySeconds: 60, amount: $pageChunk->count());
// ... do things
Steps To Reproduce
I'm not sure how to reproduce this - it has happened once in 6 months.