Open congyiwu opened 5 years ago
BTW @lferrao, I think this is the same issue as dotnet/runtime#26989, which you filed. It's possible that your issue only repros in the debugger because there's a slightly longer delay? I aws able to repro my issue w/ a release build outside of VS.
Thanks @congyiwu, that makes sense, I'll keep an eye open for this one as well.
Here's a minimal repro w/ .NET Core 2.1:
I assumed [1] that canceling a
BufferBlock
would guarantee completion, but this doesn't appear to be the case:cts.Cancel()
immediately afterb.Complete()
, thenawait b.Completion
throwsTaskCanceledException
as expected.b.Complete()
before callingcts.Cancel()
,await b.Completion
hangs indefinitely, which is unexpected.b.LinkTo(DataflowBlock.NullTarget<int>());
immediately after callingcts.Cancel();
, thenawait b.Completion
throwsTaskCanceledException
(huh?).Is this behavior expected? If so, is there a better way to "completely" cancel a BufferBlock more or less immediately?
In my actual product code, I have a
BufferBlock src
linked to anActionBlock tgt
. Sometimestgt
completes/faults beforesrc
. When that happens, I cancelsrc
and wait forsrc.Completion
, which hangs. I could simply stop waiting forsrc.Completion
if that's the right thing to do.It seems like the only consequence would be a memory leak while the VS debugger is attached (#30582), which is OK.
[1] I couldn't find any documentation that contradicted (or supported) my assumptions: https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/dataflow-task-parallel-library https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.dataflow.bufferblock-1.completion?view=netcore-2.1 https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.dataflow.dataflowblockoptions.cancellationtoken?view=netcore-2.1