Skip to content

fix: RateLimit memory leak regression (v0.5.3 hotfix) - #17

Merged
kolkov merged 1 commit into
mainfrom
fix/ratelimit-regression
Sep 10, 2026
Merged

fix: RateLimit memory leak regression (v0.5.3 hotfix)#17
kolkov merged 1 commit into
mainfrom
fix/ratelimit-regression

Conversation

@kolkov

@kolkov kolkov commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Hotfix

Regression in v0.5.2: insertOrd slice grew unbounded — Cleanup removed from map but not from tracking slice. 50K unique keys → 50K stale entries while map=0.

Fix: Replaced insertOrd []string with proper LRU via container/list + map[string]*list.Element. GetLimiter does MoveToBack (true LRU). Cleanup removes from both structures.

TDD: 2 regression tests (memory leak repro, duplicate key eviction).

Found by Fable 5.1 re-validation of v0.5.2.

REGRESSION in v0.5.2: insertOrd slice grew unbounded because Cleanup()
removed keys from map but not from insertOrd. Replaced with proper
LRU using container/list + map[string]*list.Element.

- GetLimiter: MoveToBack on access (true LRU, not FIFO)
- Cleanup: removes from both map and LRU list
- evictLRU: O(1) via list.Front + Remove
- No stale entries, no duplicate keys
- TDD: 2 regression tests (leak repro, duplicate key eviction)
@kolkov
kolkov merged commit 261bceb into main Sep 10, 2026
5 checks passed
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
middleware/ratelimit.go 95.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@kolkov
kolkov deleted the fix/ratelimit-regression branch September 10, 2026 21:08
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.

1 participant