You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DataflowLinkOptions.MaxMessages is ignored when I make a link from a source block to a propagator block created by DataflowBlock.Encapsulate method. I could not find out this behavior in the documentation.
Repro
using System;using System.Threading;using System.Threading.Tasks;using System.Threading.Tasks.Dataflow;classProgram{staticvoidMain(string[]args){var(propagator, actualTargetBlock)= CreatePropagator();varoutputBlock=newActionBlock<int>(async i =>{ Console.WriteLine(i);await Task.Delay(500);// Delay to postpone offer},new ExecutionDataflowBlockOptions(){BoundedCapacity=1});
propagator.LinkTo(outputBlock);// sourceBlock emits 1, 2, 3, 4, 5varsourceBlock=newBufferBlock<int>();for(vari=1;i <= 5;i++) sourceBlock.Post(i);
sourceBlock.LinkTo(propagator,new DataflowLinkOptions(){MaxMessages=2});// Here works as expected:// sourceBlock.LinkTo(actualTargetBlock, new DataflowLinkOptions() { MaxMessages = 2 });
Thread.Sleep(5000);}static(IPropagatorBlock<int,int>,ITargetBlock<int>)CreatePropagator(){// Set 1 to BoundedCapacity to postpone offersvarbufferBlock=newBufferBlock<int>(new DataflowBlockOptions(){BoundedCapacity=1});vardoNothingTransformBlock=newTransformBlock<int,int>(x => x,new ExecutionDataflowBlockOptions(){BoundedCapacity=1});
bufferBlock.LinkTo(doNothingTransformBlock,new DataflowLinkOptions(){PropagateCompletion=true});varpropagator= DataflowBlock.Encapsulate(bufferBlock, doNothingTransformBlock);return(propagator, bufferBlock);}}
Expected output:
1
2
Actual output:
1
2
3
4
5
The text was updated successfully, but these errors were encountered:
I took a look at the repro, and the problem is specific to the case where the encapsulated target of the block postpones messages (this is happening in the repro because the targets are bounded, and there's enough back pressure to cause the target buffer block to postpone rather than immediately accept). When the target block then has space free up and it goes back to the original source to ask for the postponed message, the accounting logic sees it as coming from the encapsulatee rather than the encapsulator and doesn't apply the intended max messages limit.
Summary
DataflowLinkOptions.MaxMessages
is ignored when I make a link from a source block to a propagator block created byDataflowBlock.Encapsulate
method. I could not find out this behavior in the documentation.Repro
Expected output:
Actual output:
The text was updated successfully, but these errors were encountered: