-
Notifications
You must be signed in to change notification settings - Fork 27
Description
The parameter permitCount is passed to both AttemptAcquire and AcquireAsync in the RateLimiter abstract base class that all rate limiters in this library are are implementing.
The definition for this paramater is as follows:
<param name="permitCount">Number of permits to try and acquire.</param>
(See for instance here: https://github.com/dotnet/runtime/blob/43a60c8ed073a4c6134facadd01c9c1c2643e41a/src/libraries/System.Threading.RateLimiting/src/System/Threading/RateLimiting/RateLimiter.cs#L60)
Yet, all the provided classes disregard this parameter value, as in here:
aspnetcore-redis-rate-limiting/src/RedisRateLimiting/SlidingWindow/RedisSlidingWindowRateLimiter.cs
Lines 51 to 59 in 808c7d8
protected override ValueTask<RateLimitLease> AcquireAsyncCore(int permitCount, CancellationToken cancellationToken) | |
{ | |
if (permitCount > _options.PermitLimit) | |
{ | |
throw new ArgumentOutOfRangeException(nameof(permitCount), permitCount, string.Format("{0} permit(s) exceeds the permit limit of {1}.", permitCount, _options.PermitLimit)); | |
} | |
return AcquireAsyncCoreInternal(); | |
} |
In some cases, a hard coded value of 1D is then passed on instead of the parameter, as in here:
aspnetcore-redis-rate-limiting/src/RedisRateLimiting/FixedWindow/RedisFixedWindowManager.cs
Lines 56 to 67 in bdca17f
var response = (RedisValue[]?)await database.ScriptEvaluateAsync( | |
_redisScript, | |
new | |
{ | |
rate_limit_key = RateLimitKey, | |
expires_at_key = RateLimitExpireKey, | |
next_expires_at = now.Add(_options.Window).ToUnixTimeSeconds(), | |
current_time = nowUnixTimeSeconds, | |
increment_amount = 1D, | |
}); | |
var result = new RedisFixedWindowResponse(); |
Are there plans to solve this?
Also, If this is currently a known limitation of this library (fair), please provide a warning in the documentation.
Thanks.