fix ChainedRateLimiter treating IdleDuration and chained ReplenishmentRateLimiters incorrectly#126158
Conversation
|
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
...raries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/ChainedRateLimiter.cs
Show resolved
Hide resolved
.../System.Threading.RateLimiting/src/System/Threading/RateLimiting/ChainedRateLimiterShared.cs
Outdated
Show resolved
Hide resolved
|
/ba-g CI keeps failing on WASM tests, not related to the actual code change. Merging |
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