ratelimit: eviction path untested and comment/policy mismatch #529

Open
opened 2026-08-04 19:36:59 +00:00 by the.auditor · 0 comments
Owner

TestEvictionBoundsMap generates IPs via fmt.Sprintf("10.0.0.%d", i%256) — only 256 distinct keys against maxIPs = 1024, so len(l.limiters) >= maxIPs is never reached and evictOneLocked is never exercised; the test passes trivially. The eviction path (the trickiest logic) is untested. Also, forIP's comment says "oldest-inserted bucket is dropped" but the implementation evicts the bucket with fewest remaining tokens.

Context: PR #526 (internal/ratelimit/ratelimit_test.go, internal/ratelimit/ratelimit.go:80).

Suggested fix: generate more than maxIPs unique IPs so eviction actually triggers, and align the comment with the fewest-tokens policy.

`TestEvictionBoundsMap` generates IPs via `fmt.Sprintf("10.0.0.%d", i%256)` — only 256 distinct keys against `maxIPs = 1024`, so `len(l.limiters) >= maxIPs` is never reached and `evictOneLocked` is never exercised; the test passes trivially. The eviction path (the trickiest logic) is untested. Also, `forIP`'s comment says "oldest-inserted bucket is dropped" but the implementation evicts the bucket with fewest remaining tokens. Context: PR #526 (`internal/ratelimit/ratelimit_test.go`, `internal/ratelimit/ratelimit.go:80`). Suggested fix: generate more than `maxIPs` unique IPs so eviction actually triggers, and align the comment with the fewest-tokens policy.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/thwap-pagesd#529
No description provided.