Skip to content

Rate Limit: Fix Memory Leak#32

Merged
keenanjohnson merged 3 commits into
mainfrom
rate-limit-memory-leak
May 21, 2026
Merged

Rate Limit: Fix Memory Leak#32
keenanjohnson merged 3 commits into
mainfrom
rate-limit-memory-leak

Conversation

@keenanjohnson
Copy link
Copy Markdown
Member

Closes #25

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #25 by adding time-based eviction of per-API-key rate limiter entries so the in-memory key map doesn’t grow without bound over time.

Changes:

  • Extend ratelimit.Limiter to track lastSeen per key and lazily evict idle keys after a configured TTL.
  • Update server wiring to configure the limiter with a 10-minute idle eviction TTL.
  • Add tests for idle eviction behavior using an injected clock (no sleeps).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
main.go Updates rate limiter construction to include an idle eviction TTL and adjusts the explanatory comment.
internal/ratelimit/ratelimit.go Implements TTL-based lazy eviction with per-key lastSeen tracking and a sweep-on-access approach.
internal/ratelimit/ratelimit_test.go Updates existing tests to use a long TTL helper and adds new tests covering eviction/retention semantics.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main.go Outdated
Comment thread internal/ratelimit/ratelimit.go Outdated
Comment thread internal/ratelimit/ratelimit.go
keenanjohnson and others added 2 commits May 21, 2026 00:31
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@keenanjohnson keenanjohnson merged commit d02e3d3 into main May 21, 2026
6 checks passed
@keenanjohnson keenanjohnson deleted the rate-limit-memory-leak branch May 21, 2026 05:33
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.

Fix Rate Limit Memory Leak

2 participants