diff options
Diffstat (limited to 'src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiter.cs')
-rw-r--r-- | src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiter.cs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiter.cs b/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiter.cs index 1dfbe7fde9e..6eace9e71f7 100644 --- a/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiter.cs +++ b/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/TokenBucketRateLimiter.cs @@ -126,7 +126,11 @@ namespace System.Threading.RateLimiting RequestRegistration oldestRequest = _queue.DequeueHead(); _queueCount -= oldestRequest.Count; Debug.Assert(_queueCount >= 0); - oldestRequest.Tcs.TrySetResult(FailedLease); + if (!oldestRequest.Tcs.TrySetResult(FailedLease)) + { + // Updating queue count is handled by the cancellation code + _queueCount += oldestRequest.Count; + } } while (_options.QueueLimit - _queueCount < tokenCount); } @@ -328,7 +332,7 @@ namespace System.Threading.RateLimiting ? _queue.DequeueHead() : _queue.DequeueTail(); next.CancellationTokenRegistration.Dispose(); - next.Tcs.SetResult(FailedLease); + next.Tcs.TrySetResult(FailedLease); } } } |