Repository navigation
fix: share rate-limit counters across routes with matching groupId (#463) - #468
Open
SameRainbows wants to merge 1 commit into
Open
SameRainbows wants to merge 1 commit into
SameRainbows wants to merge 1 commit into
Conversation
2 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #463
Description
When routes configure a
groupId, the group identifier is appended to the rate-limit key, but each route previously received a distinct storage partition:LocalStore.prototype.child, a newLocalStoreinstance was created with a fresh LRU cache per route, meaning counters on identical keys across different routes never collided.RedisStore.prototype.child, the namespace was hardcoded torouteOptions.routeInfo.method + routeOptions.routeInfo.url, prefixing the route before the key.As a result, N routes in the same group each allowed the full
maxquota, rather than sharing a single quota as intended.Changes
LocalStore.prototype.child: whenrouteOptions.groupIdis provided, reuse the parent store's LRU cache so matching group keys collide as expected.RedisStore.prototype.child: whenrouteOptions.groupIdis provided, use the group identifier as the key prefix namespace instead of method + URL.groupIdis present.test/group-rate-limit.test.jsverifying shared group counters, independent counters without groupId, and RedisStore child namespacing.test/redis-rate-limit.test.jsverifying shared counters when Redis is running.