diff --git a/src/libraries/System.Threading.RateLimiting/ref/System.Threading.RateLimiting.cs b/src/libraries/System.Threading.RateLimiting/ref/System.Threading.RateLimiting.cs index 9ca87ccd8cff4..70be12aed58a7 100644 --- a/src/libraries/System.Threading.RateLimiting/ref/System.Threading.RateLimiting.cs +++ b/src/libraries/System.Threading.RateLimiting/ref/System.Threading.RateLimiting.cs @@ -29,8 +29,8 @@ public FixedWindowRateLimiter(System.Threading.RateLimiting.FixedWindowRateLimit public override System.TimeSpan? IdleDuration { get { throw null; } } public override bool IsAutoReplenishing { get { throw null; } } public override System.TimeSpan ReplenishmentPeriod { get { throw null; } } - protected override System.Threading.Tasks.ValueTask AcquireAsyncCore(int requestCount, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - protected override System.Threading.RateLimiting.RateLimitLease AttemptAcquireCore(int requestCount) { throw null; } + protected override System.Threading.Tasks.ValueTask AcquireAsyncCore(int permitCount, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + protected override System.Threading.RateLimiting.RateLimitLease AttemptAcquireCore(int permitCount) { throw null; } protected override void Dispose(bool disposing) { } protected override System.Threading.Tasks.ValueTask DisposeAsyncCore() { throw null; } public override System.Threading.RateLimiting.RateLimiterStatistics? GetStatistics() { throw null; } @@ -150,8 +150,8 @@ public SlidingWindowRateLimiter(System.Threading.RateLimiting.SlidingWindowRateL public override System.TimeSpan? IdleDuration { get { throw null; } } public override bool IsAutoReplenishing { get { throw null; } } public override System.TimeSpan ReplenishmentPeriod { get { throw null; } } - protected override System.Threading.Tasks.ValueTask AcquireAsyncCore(int requestCount, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } - protected override System.Threading.RateLimiting.RateLimitLease AttemptAcquireCore(int requestCount) { throw null; } + protected override System.Threading.Tasks.ValueTask AcquireAsyncCore(int permitCount, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + protected override System.Threading.RateLimiting.RateLimitLease AttemptAcquireCore(int permitCount) { throw null; } protected override void Dispose(bool disposing) { } protected override System.Threading.Tasks.ValueTask DisposeAsyncCore() { throw null; } public override System.Threading.RateLimiting.RateLimiterStatistics? GetStatistics() { throw null; } diff --git a/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs b/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs index 780eddd2cee2e..381f7038fc60b 100644 --- a/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs +++ b/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/FixedWindowRateLimiter.cs @@ -13,7 +13,7 @@ namespace System.Threading.RateLimiting /// public sealed class FixedWindowRateLimiter : ReplenishingRateLimiter { - private int _requestCount; + private int _permitCount; private int _queueCount; private long _lastReplenishmentTick; private long? _idleSince; @@ -73,7 +73,7 @@ public FixedWindowRateLimiter(FixedWindowRateLimiterOptions options) AutoReplenishment = options.AutoReplenishment }; - _requestCount = options.PermitLimit; + _permitCount = options.PermitLimit; _idleSince = _lastReplenishmentTick = Stopwatch.GetTimestamp(); @@ -89,7 +89,7 @@ public FixedWindowRateLimiter(FixedWindowRateLimiterOptions options) ThrowIfDisposed(); return new RateLimiterStatistics() { - CurrentAvailablePermits = _requestCount, + CurrentAvailablePermits = _permitCount, CurrentQueuedCount = _queueCount, TotalFailedLeases = Interlocked.Read(ref _failedLeasesCount), TotalSuccessfulLeases = Interlocked.Read(ref _successfulLeasesCount), @@ -97,55 +97,55 @@ public FixedWindowRateLimiter(FixedWindowRateLimiterOptions options) } /// - protected override RateLimitLease AttemptAcquireCore(int requestCount) + protected override RateLimitLease AttemptAcquireCore(int permitCount) { // These amounts of resources can never be acquired // Raises a PermitLimitExceeded ArgumentOutOFRangeException - if (requestCount > _options.PermitLimit) + if (permitCount > _options.PermitLimit) { - throw new ArgumentOutOfRangeException(nameof(requestCount), requestCount, SR.Format(SR.PermitLimitExceeded, requestCount, _options.PermitLimit)); + throw new ArgumentOutOfRangeException(nameof(permitCount), permitCount, SR.Format(SR.PermitLimitExceeded, permitCount, _options.PermitLimit)); } // Return SuccessfulLease or FailedLease depending to indicate limiter state - if (requestCount == 0 && !_disposed) + if (permitCount == 0 && !_disposed) { // Check if the requests are permitted in a window // Requests will be allowed if the total served request is less than the max allowed requests (permit limit). - if (_requestCount > 0) + if (_permitCount > 0) { Interlocked.Increment(ref _successfulLeasesCount); return SuccessfulLease; } Interlocked.Increment(ref _failedLeasesCount); - return CreateFailedWindowLease(requestCount); + return CreateFailedWindowLease(permitCount); } lock (Lock) { - if (TryLeaseUnsynchronized(requestCount, out RateLimitLease? lease)) + if (TryLeaseUnsynchronized(permitCount, out RateLimitLease? lease)) { return lease; } Interlocked.Increment(ref _failedLeasesCount); - return CreateFailedWindowLease(requestCount); + return CreateFailedWindowLease(permitCount); } } /// - protected override ValueTask AcquireAsyncCore(int requestCount, CancellationToken cancellationToken = default) + protected override ValueTask AcquireAsyncCore(int permitCount, CancellationToken cancellationToken = default) { // These amounts of resources can never be acquired - if (requestCount > _options.PermitLimit) + if (permitCount > _options.PermitLimit) { - throw new ArgumentOutOfRangeException(nameof(requestCount), requestCount, SR.Format(SR.PermitLimitExceeded, requestCount, _options.PermitLimit)); + throw new ArgumentOutOfRangeException(nameof(permitCount), permitCount, SR.Format(SR.PermitLimitExceeded, permitCount, _options.PermitLimit)); } ThrowIfDisposed(); - // Return SuccessfulAcquisition if requestCount is 0 and resources are available - if (requestCount == 0 && _requestCount > 0) + // Return SuccessfulAcquisition if permitCount is 0 and resources are available + if (permitCount == 0 && _permitCount > 0) { Interlocked.Increment(ref _successfulLeasesCount); return new ValueTask(SuccessfulLease); @@ -153,16 +153,16 @@ protected override ValueTask AcquireAsyncCore(int requestCount, lock (Lock) { - if (TryLeaseUnsynchronized(requestCount, out RateLimitLease? lease)) + if (TryLeaseUnsynchronized(permitCount, out RateLimitLease? lease)) { return new ValueTask(lease); } // Avoid integer overflow by using subtraction instead of addition Debug.Assert(_options.QueueLimit >= _queueCount); - if (_options.QueueLimit - _queueCount < requestCount) + if (_options.QueueLimit - _queueCount < permitCount) { - if (_options.QueueProcessingOrder == QueueProcessingOrder.NewestFirst && requestCount <= _options.QueueLimit) + if (_options.QueueProcessingOrder == QueueProcessingOrder.NewestFirst && permitCount <= _options.QueueLimit) { // remove oldest items from queue until there is space for the newest acquisition request do @@ -179,17 +179,17 @@ protected override ValueTask AcquireAsyncCore(int requestCount, Interlocked.Increment(ref _failedLeasesCount); } } - while (_options.QueueLimit - _queueCount < requestCount); + while (_options.QueueLimit - _queueCount < permitCount); } else { Interlocked.Increment(ref _failedLeasesCount); // Don't queue if queue limit reached and QueueProcessingOrder is OldestFirst - return new ValueTask(CreateFailedWindowLease(requestCount)); + return new ValueTask(CreateFailedWindowLease(permitCount)); } } - CancelQueueState tcs = new CancelQueueState(requestCount, this, cancellationToken); + CancelQueueState tcs = new CancelQueueState(permitCount, this, cancellationToken); CancellationTokenRegistration ctr = default; if (cancellationToken.CanBeCanceled) { @@ -199,32 +199,32 @@ protected override ValueTask AcquireAsyncCore(int requestCount, }, tcs); } - RequestRegistration registration = new RequestRegistration(requestCount, tcs, ctr); + RequestRegistration registration = new RequestRegistration(permitCount, tcs, ctr); _queue.EnqueueTail(registration); - _queueCount += requestCount; + _queueCount += permitCount; Debug.Assert(_queueCount <= _options.QueueLimit); return new ValueTask(registration.Tcs.Task); } } - private RateLimitLease CreateFailedWindowLease(int requestCount) + private RateLimitLease CreateFailedWindowLease(int permitCount) { - int replenishAmount = requestCount - _requestCount + _queueCount; + int replenishAmount = permitCount - _permitCount + _queueCount; // can't have 0 replenish window, that would mean it should be a successful lease int replenishWindow = Math.Max(replenishAmount / _options.PermitLimit, 1); return new FixedWindowLease(false, TimeSpan.FromTicks(_options.Window.Ticks * replenishWindow)); } - private bool TryLeaseUnsynchronized(int requestCount, [NotNullWhen(true)] out RateLimitLease? lease) + private bool TryLeaseUnsynchronized(int permitCount, [NotNullWhen(true)] out RateLimitLease? lease) { ThrowIfDisposed(); // if permitCount is 0 we want to queue it if there are no available permits - if (_requestCount >= requestCount && _requestCount != 0) + if (_permitCount >= permitCount && _permitCount != 0) { - if (requestCount == 0) + if (permitCount == 0) { Interlocked.Increment(ref _successfulLeasesCount); // Edge case where the check before the lock showed 0 available permit counters but when we got the lock, some permits were now available @@ -237,8 +237,8 @@ private bool TryLeaseUnsynchronized(int requestCount, [NotNullWhen(true)] out Ra if (_queueCount == 0 || (_queueCount > 0 && _options.QueueProcessingOrder == QueueProcessingOrder.NewestFirst)) { _idleSince = null; - _requestCount -= requestCount; - Debug.Assert(_requestCount >= 0); + _permitCount -= permitCount; + Debug.Assert(_permitCount >= 0); Interlocked.Increment(ref _successfulLeasesCount); lease = SuccessfulLease; return true; @@ -294,15 +294,15 @@ private void ReplenishInternal(long nowTicks) _lastReplenishmentTick = nowTicks; - int availableRequestCounters = _requestCount; + int availablePermitCounters = _permitCount; - if (availableRequestCounters >= _options.PermitLimit) + if (availablePermitCounters >= _options.PermitLimit) { // All counters available, nothing to do return; } - _requestCount = _options.PermitLimit; + _permitCount = _options.PermitLimit; // Process queued requests while (_queue.Count > 0) @@ -312,7 +312,7 @@ private void ReplenishInternal(long nowTicks) ? _queue.PeekHead() : _queue.PeekTail(); - if (_requestCount >= nextPendingRequest.Count) + if (_permitCount >= nextPendingRequest.Count) { // Request can be fulfilled nextPendingRequest = @@ -321,13 +321,13 @@ private void ReplenishInternal(long nowTicks) : _queue.DequeueTail(); _queueCount -= nextPendingRequest.Count; - _requestCount -= nextPendingRequest.Count; - Debug.Assert(_requestCount >= 0); + _permitCount -= nextPendingRequest.Count; + Debug.Assert(_permitCount >= 0); if (!nextPendingRequest.Tcs.TrySetResult(SuccessfulLease)) { // Queued item was canceled so add count back - _requestCount += nextPendingRequest.Count; + _permitCount += nextPendingRequest.Count; // Updating queue count is handled by the cancellation code _queueCount += nextPendingRequest.Count; } @@ -345,7 +345,7 @@ private void ReplenishInternal(long nowTicks) } } - if (_requestCount == _options.PermitLimit) + if (_permitCount == _options.PermitLimit) { Debug.Assert(_idleSince is null); Debug.Assert(_queueCount == 0); @@ -426,9 +426,9 @@ public override bool TryGetMetadata(string metadataName, out object? metadata) private readonly struct RequestRegistration { - public RequestRegistration(int requestCount, TaskCompletionSource tcs, CancellationTokenRegistration cancellationTokenRegistration) + public RequestRegistration(int permitCount, TaskCompletionSource tcs, CancellationTokenRegistration cancellationTokenRegistration) { - Count = requestCount; + Count = permitCount; // Use VoidAsyncOperationWithData instead Tcs = tcs; CancellationTokenRegistration = cancellationTokenRegistration; @@ -443,14 +443,14 @@ public RequestRegistration(int requestCount, TaskCompletionSource { - private readonly int _requestCount; + private readonly int _permitCount; private readonly FixedWindowRateLimiter _limiter; private readonly CancellationToken _cancellationToken; - public CancelQueueState(int requestCount, FixedWindowRateLimiter limiter, CancellationToken cancellationToken) + public CancelQueueState(int permitCount, FixedWindowRateLimiter limiter, CancellationToken cancellationToken) : base(TaskCreationOptions.RunContinuationsAsynchronously) { - _requestCount = requestCount; + _permitCount = permitCount; _limiter = limiter; _cancellationToken = cancellationToken; } @@ -461,7 +461,7 @@ public CancelQueueState(int requestCount, FixedWindowRateLimiter limiter, Cancel { lock (_limiter.Lock) { - _limiter._queueCount -= _requestCount; + _limiter._queueCount -= _permitCount; } return true; } diff --git a/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/SlidingWindowRateLimiter.cs b/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/SlidingWindowRateLimiter.cs index 5dfc36914487e..1db6c8e9cbb39 100644 --- a/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/SlidingWindowRateLimiter.cs +++ b/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/SlidingWindowRateLimiter.cs @@ -13,7 +13,7 @@ namespace System.Threading.RateLimiting /// public sealed class SlidingWindowRateLimiter : ReplenishingRateLimiter { - private int _requestCount; + private int _permitCount; private int _queueCount; private int[] _requestsPerSegment; private int _currentSegmentIndex; @@ -78,7 +78,7 @@ public SlidingWindowRateLimiter(SlidingWindowRateLimiterOptions options) AutoReplenishment = options.AutoReplenishment }; - _requestCount = options.PermitLimit; + _permitCount = options.PermitLimit; _replenishmentPeriod = new TimeSpan(_options.Window.Ticks / _options.SegmentsPerWindow); // _requestsPerSegment holds the no. of acquired requests in each window segment @@ -99,7 +99,7 @@ public SlidingWindowRateLimiter(SlidingWindowRateLimiterOptions options) ThrowIfDisposed(); return new RateLimiterStatistics() { - CurrentAvailablePermits = _requestCount, + CurrentAvailablePermits = _permitCount, CurrentQueuedCount = _queueCount, TotalFailedLeases = Interlocked.Read(ref _failedLeasesCount), TotalSuccessfulLeases = Interlocked.Read(ref _successfulLeasesCount), @@ -107,18 +107,18 @@ public SlidingWindowRateLimiter(SlidingWindowRateLimiterOptions options) } /// - protected override RateLimitLease AttemptAcquireCore(int requestCount) + protected override RateLimitLease AttemptAcquireCore(int permitCount) { // These amounts of resources can never be acquired - if (requestCount > _options.PermitLimit) + if (permitCount > _options.PermitLimit) { - throw new ArgumentOutOfRangeException(nameof(requestCount), requestCount, SR.Format(SR.PermitLimitExceeded, requestCount, _options.PermitLimit)); + throw new ArgumentOutOfRangeException(nameof(permitCount), permitCount, SR.Format(SR.PermitLimitExceeded, permitCount, _options.PermitLimit)); } // Return SuccessfulLease or FailedLease depending to indicate limiter state - if (requestCount == 0 && !_disposed) + if (permitCount == 0 && !_disposed) { - if (_requestCount > 0) + if (_permitCount > 0) { Interlocked.Increment(ref _successfulLeasesCount); return SuccessfulLease; @@ -130,7 +130,7 @@ protected override RateLimitLease AttemptAcquireCore(int requestCount) lock (Lock) { - if (TryLeaseUnsynchronized(requestCount, out RateLimitLease? lease)) + if (TryLeaseUnsynchronized(permitCount, out RateLimitLease? lease)) { return lease; } @@ -142,18 +142,18 @@ protected override RateLimitLease AttemptAcquireCore(int requestCount) } /// - protected override ValueTask AcquireAsyncCore(int requestCount, CancellationToken cancellationToken = default) + protected override ValueTask AcquireAsyncCore(int permitCount, CancellationToken cancellationToken = default) { // These amounts of resources can never be acquired - if (requestCount > _options.PermitLimit) + if (permitCount > _options.PermitLimit) { - throw new ArgumentOutOfRangeException(nameof(requestCount), requestCount, SR.Format(SR.PermitLimitExceeded, requestCount, _options.PermitLimit)); + throw new ArgumentOutOfRangeException(nameof(permitCount), permitCount, SR.Format(SR.PermitLimitExceeded, permitCount, _options.PermitLimit)); } ThrowIfDisposed(); // Return SuccessfulAcquisition if resources are available - if (requestCount == 0 && _requestCount > 0) + if (permitCount == 0 && _permitCount > 0) { Interlocked.Increment(ref _successfulLeasesCount); return new ValueTask(SuccessfulLease); @@ -161,16 +161,16 @@ protected override ValueTask AcquireAsyncCore(int requestCount, lock (Lock) { - if (TryLeaseUnsynchronized(requestCount, out RateLimitLease? lease)) + if (TryLeaseUnsynchronized(permitCount, out RateLimitLease? lease)) { return new ValueTask(lease); } // Avoid integer overflow by using subtraction instead of addition Debug.Assert(_options.QueueLimit >= _queueCount); - if (_options.QueueLimit - _queueCount < requestCount) + if (_options.QueueLimit - _queueCount < permitCount) { - if (_options.QueueProcessingOrder == QueueProcessingOrder.NewestFirst && requestCount <= _options.QueueLimit) + if (_options.QueueProcessingOrder == QueueProcessingOrder.NewestFirst && permitCount <= _options.QueueLimit) { // Remove oldest items from queue until there is space for the newest acquisition request do @@ -187,7 +187,7 @@ protected override ValueTask AcquireAsyncCore(int requestCount, Interlocked.Increment(ref _failedLeasesCount); } } - while (_options.QueueLimit - _queueCount < requestCount); + while (_options.QueueLimit - _queueCount < permitCount); } else { @@ -197,7 +197,7 @@ protected override ValueTask AcquireAsyncCore(int requestCount, } } - CancelQueueState tcs = new CancelQueueState(requestCount, this, cancellationToken); + CancelQueueState tcs = new CancelQueueState(permitCount, this, cancellationToken); CancellationTokenRegistration ctr = default; if (cancellationToken.CanBeCanceled) { @@ -207,23 +207,23 @@ protected override ValueTask AcquireAsyncCore(int requestCount, }, tcs); } - RequestRegistration registration = new RequestRegistration(requestCount, tcs, ctr); + RequestRegistration registration = new RequestRegistration(permitCount, tcs, ctr); _queue.EnqueueTail(registration); - _queueCount += requestCount; + _queueCount += permitCount; Debug.Assert(_queueCount <= _options.QueueLimit); return new ValueTask(registration.Tcs.Task); } } - private bool TryLeaseUnsynchronized(int requestCount, [NotNullWhen(true)] out RateLimitLease? lease) + private bool TryLeaseUnsynchronized(int permitCount, [NotNullWhen(true)] out RateLimitLease? lease) { ThrowIfDisposed(); - // if requestCount is 0 we want to queue it if there are no available permits - if (_requestCount >= requestCount && _requestCount != 0) + // if permitCount is 0 we want to queue it if there are no available permits + if (_permitCount >= permitCount && _permitCount != 0) { - if (requestCount == 0) + if (permitCount == 0) { Interlocked.Increment(ref _successfulLeasesCount); // Edge case where the check before the lock showed 0 available permits but when we got the lock some permits were now available @@ -236,9 +236,9 @@ private bool TryLeaseUnsynchronized(int requestCount, [NotNullWhen(true)] out Ra if (_queueCount == 0 || (_queueCount > 0 && _options.QueueProcessingOrder == QueueProcessingOrder.NewestFirst)) { _idleSince = null; - _requestsPerSegment[_currentSegmentIndex] += requestCount; - _requestCount -= requestCount; - Debug.Assert(_requestCount >= 0); + _requestsPerSegment[_currentSegmentIndex] += permitCount; + _permitCount -= permitCount; + Debug.Assert(_permitCount >= 0); Interlocked.Increment(ref _successfulLeasesCount); lease = SuccessfulLease; return true; @@ -299,16 +299,16 @@ private void ReplenishInternal(long nowTicks) // Increment the current segment index while move the window // We need to know the no. of requests that were acquired in a segment previously to ensure that we don't acquire more than the permit limit. _currentSegmentIndex = (_currentSegmentIndex + 1) % _options.SegmentsPerWindow; - int oldSegmentRequestCount = _requestsPerSegment[_currentSegmentIndex]; + int oldSegmentPermitCount = _requestsPerSegment[_currentSegmentIndex]; _requestsPerSegment[_currentSegmentIndex] = 0; - if (oldSegmentRequestCount == 0) + if (oldSegmentPermitCount == 0) { return; } - _requestCount += oldSegmentRequestCount; - Debug.Assert(_requestCount <= _options.PermitLimit); + _permitCount += oldSegmentPermitCount; + Debug.Assert(_permitCount <= _options.PermitLimit); // Process queued requests while (_queue.Count > 0) @@ -319,7 +319,7 @@ private void ReplenishInternal(long nowTicks) : _queue.PeekTail(); // If we have enough permits after replenishing to serve the queued requests - if (_requestCount >= nextPendingRequest.Count) + if (_permitCount >= nextPendingRequest.Count) { // Request can be fulfilled nextPendingRequest = @@ -328,14 +328,14 @@ private void ReplenishInternal(long nowTicks) : _queue.DequeueTail(); _queueCount -= nextPendingRequest.Count; - _requestCount -= nextPendingRequest.Count; + _permitCount -= nextPendingRequest.Count; _requestsPerSegment[_currentSegmentIndex] += nextPendingRequest.Count; - Debug.Assert(_requestCount >= 0); + Debug.Assert(_permitCount >= 0); if (!nextPendingRequest.Tcs.TrySetResult(SuccessfulLease)) { // Queued item was canceled so add count back - _requestCount += nextPendingRequest.Count; + _permitCount += nextPendingRequest.Count; _requestsPerSegment[_currentSegmentIndex] -= nextPendingRequest.Count; // Updating queue count is handled by the cancellation code _queueCount += nextPendingRequest.Count; @@ -354,7 +354,7 @@ private void ReplenishInternal(long nowTicks) } } - if (_requestCount == _options.PermitLimit) + if (_permitCount == _options.PermitLimit) { Debug.Assert(_idleSince is null); Debug.Assert(_queueCount == 0); @@ -435,9 +435,9 @@ public override bool TryGetMetadata(string metadataName, out object? metadata) private readonly struct RequestRegistration { - public RequestRegistration(int requestCount, TaskCompletionSource tcs, CancellationTokenRegistration cancellationTokenRegistration) + public RequestRegistration(int permitCount, TaskCompletionSource tcs, CancellationTokenRegistration cancellationTokenRegistration) { - Count = requestCount; + Count = permitCount; // Use VoidAsyncOperationWithData instead Tcs = tcs; CancellationTokenRegistration = cancellationTokenRegistration; @@ -452,14 +452,14 @@ public RequestRegistration(int requestCount, TaskCompletionSource { - private readonly int _requestCount; + private readonly int _permitCount; private readonly SlidingWindowRateLimiter _limiter; private readonly CancellationToken _cancellationToken; - public CancelQueueState(int requestCount, SlidingWindowRateLimiter limiter, CancellationToken cancellationToken) + public CancelQueueState(int permitCount, SlidingWindowRateLimiter limiter, CancellationToken cancellationToken) : base(TaskCreationOptions.RunContinuationsAsynchronously) { - _requestCount = requestCount; + _permitCount = permitCount; _limiter = limiter; _cancellationToken = cancellationToken; } @@ -470,7 +470,7 @@ public CancelQueueState(int requestCount, SlidingWindowRateLimiter limiter, Canc { lock (_limiter.Lock) { - _limiter._queueCount -= _requestCount; + _limiter._queueCount -= _permitCount; } return true; }