Produce different keys for inline ratelimiting policies - #68521
Open
Youssef1313 wants to merge 1 commit into
Open
Produce different keys for inline ratelimiting policies#68521Youssef1313 wants to merge 1 commit into
Youssef1313 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a rate-limiting correctness issue where inline RequireRateLimiting(IRateLimiterPolicy<T>) policies could unintentionally share cached limiters when they produced equal partition keys, causing cross-policy collisions and incorrect limiter configuration being applied.
Changes:
- Namespaces inline policy partition keys so distinct inline policy instances no longer collide when producing equal partition keys.
- Adds tests verifying (1) two different inline policy instances don’t share a limiter for the same key, and (2) the same policy instance reused across endpoints still shares.
- Introduces a small stateful test
RateLimiter/policy to observe limiter sharing vs isolation behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Middleware/RateLimiting/src/RateLimiterEndpointConventionBuilderExtensions.cs | Adds a per-inline-policy namespace token to avoid cross-policy partition collisions. |
| src/Middleware/RateLimiting/test/RateLimitingMiddlewareTests.cs | Adds regression tests and a small counting limiter/policy to validate isolation vs sharing behavior. |
Suppressed comments (1)
src/Middleware/RateLimiting/test/RateLimitingMiddlewareTests.cs:740
- CountingRateLimiter.GetStatistics returns null even though the overridden return type is non-nullable. This can produce nullable warnings and may break the build if warnings are treated as errors. Prefer throwing NotImplementedException (consistent with other test limiters) since the test doesn't use statistics.
public override RateLimiterStatistics GetStatistics() => null;
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
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 #67326