Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: System.Threading.RateLimiting RateLimitLease should implement IAsyncDisposable #77669

Open
cristipufu opened this issue Oct 31, 2022 · 4 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Threading
Milestone

Comments

@cristipufu
Copy link

Background and motivation

Hi, I'm working on a Redis extension library on top of Microsoft.AspNetCore.RateLimiting (for multi-node deployments), using the new Rate Limiting support added in NET 7: https://github.com/cristipufu/aspnetcore-redis-rate-limiting

When the ConcurrencyLimiter's ConcurrencyLease gets disposed, we need to basically decrement the count for that particular policy. At the moment, the current API forces me to use the sync version.

My suggestion would be to make RateLimitLease implement IAsyncDisposable, such that we can call async APIs when the lease is released: https://github.com/cristipufu/aspnetcore-redis-rate-limiting/blob/master/src/RedisRateLimiting/Concurrency/RedisConcurrencyRateLimiter.cs#L114

API Proposal

namespace System.Threading.RateLimiting
{
    public abstract class RateLimitLease : IDisposable, IAsyncDisposable
    {
        ...

       protected virtual ValueTask DisposeAsync(bool disposing)
       {
           return default;
       }

        public ValueTask DisposeAsync()
        {
            return DisposeAsync(true);
        }
    }
}

API Usage

private sealed class RedisConcurrencyLease : RateLimitLease
{
     ...

    protected override ValueTask DisposeAsync(bool disposing)
    {
        if (_disposed)
        {
            return;
        }

        _disposed = true;

        if (_id != null)
        {
            return _limiter?.ReleaseAsync(_id);
        }

       return default;
    }
}

Alternative Designs

No response

Risks

No response

@cristipufu cristipufu added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Oct 31, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 31, 2022
@ghost
Copy link

ghost commented Oct 31, 2022

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

Hi, I'm working on a Redis extension library on top of Microsoft.AspNetCore.RateLimiting (for multi-node deployments), using the new Rate Limiting support added in NET 7: https://github.com/cristipufu/aspnetcore-redis-rate-limiting

When the ConcurrencyLimiter's ConcurrencyLease gets disposed, we need to basically decrement the count for that particular policy. At the moment, the current API forces me to use the sync version.

My suggestion would be to make RateLimitLease implement IAsyncDisposable, such that we can call async APIs when the lease is released: https://github.com/cristipufu/aspnetcore-redis-rate-limiting/blob/master/src/RedisRateLimiting/Concurrency/RedisConcurrencyRateLimiter.cs#L114

API Proposal

namespace System.Threading.RateLimiting
{
    public abstract class RateLimitLease : IDisposable, IAsyncDisposable
    {
        ...

       protected virtual ValueTask DisposeAsync(bool disposing)
       {
           return default;
       }

        public ValueTask DisposeAsync()
        {
            return DisposeAsync(true);
        }
    }
}

API Usage

private sealed class RedisConcurrencyLease : RateLimitLease
{
     ...

    protected override ValueTask DisposeAsync(bool disposing)
    {
        if (_disposed)
        {
            return;
        }

        _disposed = true;

        if (_id != null)
        {
            return _limiter?.ReleaseAsync(_id);
        }

       return default;
    }
}

Alternative Designs

No response

Risks

No response

Author: cristipufu
Assignees: -
Labels:

api-suggestion, area-System.Threading, untriaged

Milestone: -

@cristipufu
Copy link
Author

@mangod9 mangod9 removed the untriaged New issue has not been triaged by the area owner label Mar 22, 2023
@mangod9 mangod9 added this to the Future milestone Mar 22, 2023
@cristipufu
Copy link
Author

Tagging @BrennanConroy @davidfowl @halter73 @JamesNK for visibility
Please take a look: cristipufu/aspnetcore-redis-rate-limiting#66

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Threading
Projects
None yet
Development

No branches or pull requests

3 participants