fix ChainedRateLimiter treating IdleDuration and chained ReplenishmentRateLimiters incorrectly#126158
fix ChainedRateLimiter treating IdleDuration and chained ReplenishmentRateLimiters incorrectly#126158DeagleGross wants to merge 5 commits intodotnet:mainfrom
ChainedRateLimiter treating IdleDuration and chained ReplenishmentRateLimiters incorrectly#126158Conversation
|
Tagging subscribers to this area: @agocke, @VSadov |
There was a problem hiding this comment.
Pull request overview
This PR fixes ChainedRateLimiter integration with PartitionedRateLimiter by correcting idle detection semantics and ensuring replenishment is invoked for replenishing limiters wrapped inside a ChainedRateLimiter.
Changes:
- Update
ChainedRateLimiter.IdleDurationto returnnullif any child limiter reportsIdleDuration == null. - Add internal
ChainedRateLimiter.TryReplenish()and call it fromDefaultPartitionedRateLimiter.Heartbeat()so inner replenishing limiters get replenished. - Add/adjust unit tests covering chained replenishment and idle-based eviction behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/ChainedRateLimiter.cs | Fixes IdleDuration semantics and adds TryReplenish() that replenishes inner replenishing limiters. |
| src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/DefaultPartitionedRateLimiter.cs | Special-cases ChainedRateLimiter during heartbeat to call its replenishment logic. |
| src/libraries/System.Threading.RateLimiting/tests/PartitionedRateLimiterTests.cs | Adds coverage ensuring heartbeat replenishes chained inner replenishing limiters and validates eviction behavior with null idle durations. |
| src/libraries/System.Threading.RateLimiting/tests/ChainedLimiterTests.cs | Updates/extends tests for the corrected IdleDuration behavior. |
...raries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/ChainedRateLimiter.cs
Outdated
Show resolved
Hide resolved
Wonder if |
Reworked like that: introduced shared static methods on |
src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/RateLimiter.cs
Show resolved
Hide resolved
BrennanConroy
left a comment
There was a problem hiding this comment.
nit: It's a bit odd to have the static shared methods inside a concrete class (ChainedRateLimiter).
Could we move the shared methods to a separate static class, similar to
There was a problem hiding this comment.
Not new in this PR, but Dispose should be disposing the inner limiters and calling base.Dispose(disposing).
And also, probably override DisposeAsyncCore.
Fixed
ChainedRateLimiter.IdleDuration. In the current PR if it detects any of chained child rateLimiters havingnullIdleDuration, it will return null now.IdleDurationequallingnowmeans rateLimiter is in use or is not ready to be idle.DefaultPartitionedRateLimiterdoes not replenish the children rateLimiters ofChainedRateLimiter. Now there are 2 implementations of chained limiter depending on the passed limiters toRateLimiter.CreateChained(...)Related #68776
Fixes #125560