ConcurrencyLimiter: a waiter cancelled during a release can leave a free permit that a queued request never gets
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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日 13時間
- マージ済み PR(30日)
- 588
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/runtime のほかの issue
-
area-System.IO untriaged
難易度 2/5 半日 初心者へのやさしさ 72/100
dotnet/runtime#136802 · コメント 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 日以内に返信
-
area-System.ComponentModel untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
dotnet/runtime#136608 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
MemoryMappedFile (Windows): failed MEM_COMMIT is ignored, accessor over reserved memory crashes the process対応中かも @RutulPatel8 が 1 日前に担当しました。 オープンarea-System.IO bug untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dotnet/runtime#136599 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area-System.IO untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
dotnet/runtime#136577 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
is:build
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
nopSolutions/nopCommerce#8440 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
RadicalCSG/com.chisel#192 ·
メンテナーはふだん 1 日以内に返信
-
area-testing p2-post-1.0 technical-debt
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
RazorConsole/RazorConsole#447 ·
メンテナーはふだん 1 日以内に返信