Skip to content

fix: eliminate unbounded memory leak in sliding-window rate limiters - #216

Open
almuslavish wants to merge 1 commit into
RiftCore00:devfrom
almuslavish:blackboxai/fix-rate-limiter-memory-leak
Open

fix: eliminate unbounded memory leak in sliding-window rate limiters#216
almuslavish wants to merge 1 commit into
RiftCore00:devfrom
almuslavish:blackboxai/fix-rate-limiter-memory-leak

Conversation

@almuslavish

Copy link
Copy Markdown

closes #193

Replace O(n) Array.shift() with batch filter() in both check() methods. Add cleanup() method to both limiters for proactive stale entry eviction. Add size getter to both limiters for memory observability. Add remove() method to createConnRateLimiter for API parity.

The per-client rate limiter (1-second window) and per-IP connection rate limiter (60-second window) now:

  • Use batch filter() instead of shift() for O(1) amortized check()
  • Expose cleanup() to remove all stale entries in one pass
  • Expose size getter (windows.size) for monitoring
  • Remove keys entirely when no active timestamps remain

Closes: issue-03-rate-limiter-memory-leak

Replace O(n) Array.shift() with batch filter() in both check() methods.
Add cleanup() method to both limiters for proactive stale entry eviction.
Add size getter to both limiters for memory observability.
Add remove() method to createConnRateLimiter for API parity.

The per-client rate limiter (1-second window) and per-IP connection rate
limiter (60-second window) now:
- Use batch filter() instead of shift() for O(1) amortized check()
- Expose cleanup() to remove all stale entries in one pass
- Expose size getter (windows.size) for monitoring
- Remove keys entirely when no active timestamps remain

Closes: issue-03-rate-limiter-memory-leak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eliminate the unbounded memory leak in sliding-window rate limiters by implementing time-bucketed eviction with amortized O(1) cleanup

1 participant