ConcurrencyLimiter: a waiter cancelled during a release can leave a free permit that a queued request never gets
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start with ConcurrencyLimiter and its queue-processing and cancellation paths; the issue provides a self-contained reproduction using OldestFirst. Run the reproduction or add a focused regression test for the cancellation, release, and new-acquire interleaving. Done when the queued request receives the free permit and the regression test passes.
由索引模型根据 Issue 内容生成。
描述
Description
With QueueProcessingOrder.OldestFirst, a ConcurrencyLimiter can end up with a free permit and a queued request that never gets it. No lease is held, so no Release ever comes to hand the permit out. The queued request waits until its own token is cancelled, and AttemptAcquire is refused while it waits.
It happens when three things coincide: a queued waiter's token is cancelled, the permit holder releases, and a new AcquireAsync arrives.
Reproduction Steps
using System.Diagnostics;
using System.Threading.RateLimiting;
// One permit, queue of 2, oldest first. Each round: A holds the permit and B waits with a token.
// Then, at the same moment, B's token is cancelled, A releases, and C calls AcquireAsync. However
// those three interleave, C should end up holding the permit, since nothing else does.
var budget = Stopwatch.StartNew();
for (var round = 1; budget.Elapsed < TimeSpan.FromMinutes(2); round++)
{
var limiter = new ConcurrencyLimiter(new ConcurrencyLimiterOptions
{
PermitLimit = 1,
QueueLimit = 2,
QueueProcessingOrder = QueueProcessingOrder.OldestFirst,
});
var a = limiter.AttemptAcquire();
using var cts = new CancellationTokenSource();
var b = limiter.AcquireAsync(1, cts.Token).AsTask();
using var start = new Barrier(3);
Task<RateLimitLease>? c = null;
await Task.WhenAll(
Task.Run(() => { start.SignalAndWait(); cts.Cancel(); }),
Task.Run(() => { start.SignalAndWait(); a.Dispose(); }),
Task.Run(() => { start.SignalAndWait(); c = limiter.AcquireAsync(1).AsTask(); }));
try { (await b).Dispose(); } catch (OperationCanceledException) { }
if (await Task.WhenAny(c!, Task.Delay(TimeSpan.FromSeconds(1))) != c)
{
var stats = limiter.GetStatistics()!;
Console.WriteLine($"Round {round}: C still waiting after 1 s, with nothing holding a permit.");
Console.WriteLine($" CurrentAvailablePermits = {stats.CurrentAvailablePermits}, CurrentQueuedCount = {stats.CurrentQueuedCount}");
Console.WriteLine($" A new AttemptAcquire is granted: {limiter.AttemptAcquire().IsAcquired}");
return 1;
}
(await c!).Dispose();
}
Console.WriteLine("No stall within 2 minutes.");
return 0;
Output:
Round 17524: C still waiting after 1 s, with nothing holding a permit.
CurrentAvailablePermits = 1, CurrentQueuedCount = 1
A new AttemptAcquire is granted: False
Expected behavior
C is granted the permit, since nothing else holds it.
Actual behavior
The permit stays available and C stays queued until its own token is cancelled. With steady traffic, each new request queues behind the free permit and times out, so the limiter grants nothing until no request is queued.
Regression?
No response
Known Workarounds
No response
Configuration
Windows 11 x64
Repro'd on both .NET 11 and 10
Other information
No response
- 主要语言
- C#
- 星标
- 18.4k
- 派生
- 5.8k
- 平均合并
- 2 天 12 小时
- 30 天内合并 PR
- 581
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/runtime 的其他 Issue
-
Incorrect loop bound in SizeOptIListSelectIterator.ToList可能已有人在做 @equmagg 于 1 天前认领。 未关闭area-System.Collections untriaged
难度 2/5 1-3 小时 新手友好度 64/100
dotnet/runtime#137126 · 1 条评论 ·
维护者通常 1 天内回复
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by design可能已有人在做 @alaricd 于 2 天前认领。 未关闭area-System.Transactions untriaged
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/runtime#137040 · 1 条评论 ·
维护者通常 1 天内回复
-
FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the file可能已有人在做 @makazeu 于 2 天前认领。 未关闭area-Extensions-FileSystem
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/runtime#136989 · 1 条评论 ·
维护者通常 1 天内回复
-
Configuration binder source generator emits unqualified List<T> when binding arrays without implicit usings可能已有人在做 @makazeu 于 2 天前认领。 未关闭area-Extensions-Configuration bug source-generator
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/runtime#136972 · 1 条评论 ·
维护者通常 1 天内回复
-
[wasi] .NET 10: WasmEnableSIMD with AOT fails because WasiApp.targets has -msimd128 commented out未关闭area-Build-mono untriaged
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
Docs typo未关闭
难度 1/5 1 小时以内 新手友好度 78/100
MonoGame/docs.monogame.github.io#328 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
space-wizards/RobustToolbox#7197 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
RicoSuter/Namotion.Interceptor#918 ·
维护者通常 1 天内回复