mirror of
https://github.com/kennethreitz/responder.git
synced 2026-06-05 14:50:19 +00:00
Fix memory leak in rate limiter
Empty bucket keys were never removed after their timestamps expired. Over time this accumulated an entry for every unique client IP that ever made a request. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,8 @@ class RateLimiter:
|
||||
now = time.time()
|
||||
cutoff = now - self.period
|
||||
self._buckets[key] = [t for t in self._buckets[key] if t > cutoff]
|
||||
if not self._buckets[key]:
|
||||
del self._buckets[key]
|
||||
|
||||
def check(self, req, resp):
|
||||
"""Check rate limit. Sets 429 status if exceeded."""
|
||||
|
||||
Reference in New Issue
Block a user