Fix NoopLimiter disposal in DefaultPartitionedRateLimiter Heartbeat#127582
Open
Copilot wants to merge 17 commits into
Open
Fix NoopLimiter disposal in DefaultPartitionedRateLimiter Heartbeat#127582Copilot wants to merge 17 commits into
Copilot wants to merge 17 commits into
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @VSadov |
Copilot
AI
changed the title
[WIP] Fix DefaultPartitionedRateLimiter to dispose NoopLimiter
Evict idle partitions whose IdleDuration is always null
Apr 29, 2026
VSadov
reviewed
Apr 29, 2026
VSadov
reviewed
Apr 29, 2026
This was referenced Apr 30, 2026
Copilot stopped reviewing on behalf of
VSadov due to an error
June 14, 2026 17:50
Comment on lines
+624
to
+630
| var limiterTypeDef = Type.GetType("System.Threading.RateLimiting.DefaultPartitionedRateLimiter`2, System.Threading.RateLimiting"); | ||
| Assert.NotNull(limiterTypeDef); | ||
| var limiterType = limiterTypeDef.MakeGenericType(typeof(TResource), typeof(TKey)); | ||
|
|
||
| var limitersField = limiterType.GetField("_limiters", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); | ||
| Assert.NotNull(limitersField); | ||
| var limitersDict = (System.Collections.IDictionary)limitersField.GetValue(limiter); |
|
|
||
| private static object GetLazyLimiterEntry<TResource, TKey>(PartitionedRateLimiter<TResource> limiter, TKey key) | ||
| { | ||
| // Use Type.GetType so that trimming can see what type we're reflecting on, but assert it's the one we got |
Comment on lines
+325
to
+327
| public RateLimiter Limiter { get; } | ||
| public long LastAccessTimestamp; | ||
| } |
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
…e in GetLazyLimiterEntry Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot
AI
changed the title
Evict idle partitions whose IdleDuration is always null
Add type-instance assertion before reflection GetValue in rate limiter test helper
Jun 14, 2026
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
Copilot
AI
changed the title
Add type-instance assertion before reflection GetValue in rate limiter test helper
Fix NoopLimiter partition eviction in DefaultPartitionedRateLimiter
Jun 14, 2026
Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com>
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
DefaultPartitionedRateLimiterso thatNoopLimiterpartitions are evicted and disposed by the Heartbeat timer, which previously never happened becauseNoopLimiter.IdleDurationalways returnsnull.Changes Made
LimiterEntrywrapper that tracks aLastAccessTimestamp(updated on eachAcquire/WaitAsynccall) alongside theRateLimiterinstance.GetIdleDuration(LimiterEntry)helper that falls back to the elapsed time since last access forNoopLimiter(whoseIdleDurationis alwaysnull), and returnsnullfor all other limiter types that returnnull(preserving the existing "do not evict" contract).is TimeSpan idleDuration && idleDuration > s_idleTimeLimitpattern (with?? TimeSpan.Zerofor the under-lock re-check), correctly handling the nullableTimeSpan?return —nullskips eviction, matching the original pattern.Volatile.Read/Volatile.Writefor atomic 64-bit timestamp access on 32-bit platforms.RateLimiterHelper.GetElapsedTime(long)overload to avoid.GetValueOrDefault()at call sites.NoopLimitereviction via Heartbeat and verifying that non-NoopLimiterpartitions withIdleDuration == nullare not evicted while active.