dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.06k stars 4.69k forks source link

Disposal of System.Threading.RateLimiting.ConcurrencyLease #93808

Open wasker opened 11 months ago

wasker commented 11 months ago

Description

It seems that ConcurrencyLimiter.AttemptAcquireCore and ConcurrencyLimiter.AcquireAsyncCore return cached instances of SuccessfulLease, FailedLease, and QueueLimitLease.

If the pattern of usage is

using var lease = rateLimiter.AtemptAcquire(1);

then all those cached instances will be disposed at some point.

Is this expected?

Reproduction Steps

Run

using var lease = rateLimiter.AtemptAcquire(1);

in the concurrent scenario and observe that SuccessfulLease / FailedLease are being disposed multiple times.

Expected behavior

Not dispose instances that were disposed earlier.

Actual behavior

Same instances are being disposed multiple times.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

ghost commented 11 months ago

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

Issue Details
### Description It seems that ConcurrencyLimiter.AttemptAcquireCore and ConcurrencyLimiter.AcquireAsyncCore return cached instances of SuccessfulLease, FailedLease, and QueueLimitLease. If the pattern of usage is ``` using var lease = rateLimiter.AtemptAcquire(1); ``` then all those cached instances will be disposed at some point. Is this expected? ### Reproduction Steps Run ``` using var lease = rateLimiter.AtemptAcquire(1); ``` in the concurrent scenario and observe that SuccessfulLease / FailedLease are being disposed multiple times. ### Expected behavior Not dispose instances that were disposed earlier. ### Actual behavior Same instances are being disposed multiple times. ### Regression? _No response_ ### Known Workarounds _No response_ ### Configuration _No response_ ### Other information _No response_
Author: wasker
Assignees: -
Labels: `area-System.Threading`, `untriaged`
Milestone: -
BrennanConroy commented 1 week ago

The cached instances don't do anything on dispose so it's not really an issue if they get disposed multiple times. Are you seeing an issue?

dotnet-policy-service[bot] commented 1 week ago

This issue has been marked needs-author-action and may be missing some important information.