Repository navigation
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
|
Tagging subscribers to this area: @dotnet/area-system-threading-channels |
b3fc9c6 to
042b7fe
Compare
|
@PranavSenthilnathan Ready for review |
|
We hit this on 10.0.13 in an audit batching forwarder, and it reproduces more easily than in #132094:
Minimal repro. A single reader calls using System.Threading.Channels;
var channel = Channel.CreateBounded<int>(new BoundedChannelOptions(100) { SingleReader = true });
var received = new SemaphoreSlim(0);
using var stop = new CancellationTokenSource();
var reader = Task.Run(async () =>
{
while (!stop.IsCancellationRequested)
{
using var timeout = CancellationTokenSource.CreateLinkedTokenSource(stop.Token);
timeout.CancelAfter(TimeSpan.FromTicks(5_000)); // 0.5 ms
try
{
await channel.Reader.ReadAsync(timeout.Token);
received.Release();
}
catch (OperationCanceledException) { }
}
});
for (var i = 1; i <= 100_000; i++)
{
if (!channel.Writer.TryWrite(i)) throw new InvalidOperationException("TryWrite returned false");
if (!await received.WaitAsync(TimeSpan.FromSeconds(5)))
{
Console.WriteLine($"{Environment.Version}: item {i} lost. TryWrite returned true, TryPeek = {channel.Reader.TryPeek(out _)}");
return 1;
}
}
stop.Cancel();
await reader;
Console.WriteLine($"{Environment.Version}: all items received");
return 0;Results on Linux x64, 100,000 items per run:
We worked around it by not cancelling channel operations: one |
|
@MarcelRoozekrans Yes would also like this merged, but seems I'm on the ignore-list by Microsoft-dev-team. Probably better to post your observations here: #132230 (Ahh sorry now see they have closed the PR for comments.. Guess new issue must be created to request back-port to NET10 like #136501 and give thumbs-up) |
Backport of #132230 to release/10.0
Kept original NET9_0_OR_GREATER though changing to NET would probably be prettier.