Skip to content

permitCount paramater values larger than 1 are currently not supported #36

Closed
@syntx

Description

@syntx

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:

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions