Bug using Encapsulate with Filtering

Answered Bug using Encapsulate with Filtering

  • Saturday, October 20, 2012 2:07 AM
     
      Has Code

    Assume I have the following code:

    public static IPropagatorBlock<TIn,TOut> CreateSampleBlock<TIn,TOut>(Func<TIn,TOut> transform)
    {
        var buffer = new BufferBlock<TOut>();
        var action = new ActionBlock<TIn>( i => buffer.Post(transform(i)));
    
        action.Completion.ContinueWith(_ => buffer.Complete(), 
            TaskContinuationOptions.OnlyOnRanToCompletion);
    
        action.Completion.ContinueWith(task => ((IDataflowBlock) buffer).Fault(task.Exception),
            TaskContinuationOptions.OnlyOnFaulted);
                
        return DataflowBlock.Encapsulate(action, buffer);
    } 

    Then I set up a simple network with filtering between links:

    var bb = new BufferBlock<int>();
    var mt = CreateSampleBlock<Int32, Int32>(i => i*2);
    var a = new ActionBlock<int>(i => Console.WriteLine(i));
    
    bb.LinkTo(mt);
    mt.LinkTo(a, i => i < 10);
    
    foreach (var s in Enumerable.Range(1,10))
    {
        bb.Post(s);
    }

    In this scenario an ArgumentException is thrown from within DataflowBlock.FilteredLinkPropagator<T>, obviously because of the following test in the implementation of ITargetBlock<T>.OfferMessage(...):

    if (source != this.m_source)
        throw new ArgumentException(Resource.Argument_InvalidSourceForFilteredLink, "source");

    m_source holds a reference to the EncapsulatingPropagator<TInput,TOutput>. The ISourceBlock<T> 'source' argument that is passed to the method however references the (encapsulated) BufferBlock<Int32>.


    • Edited by A.Frischke Saturday, October 20, 2012 2:09 AM
    •  

All Replies

  • Tuesday, October 30, 2012 2:05 AM
    Owner
     
     Answered

    Hi A.Frischke,

    Thank you for reporting this issue. This is a bug in Dataflow. It will be fixed in a future release.

    Thanks,Cristina

  • Friday, January 04, 2013 9:31 PM
    Owner
     
     

    Hi A.Frischke,

    The bug was fixed in the latest version of the TPL Dataflow. TPL Dataflow NuGet package version 4.5.9.<o:p></o:p>

    Please report any new issues/suggestions for TPL Dataflow; we will be happy to help.

    Thanks, Cristina<o:p></o:p>


  • Thursday, January 31, 2013 11:10 AM
     
     

    Hi Cristina,

    Great to hear that the issue has been resolved. I will test the new version right away (and keep you posted should I come across any other issues in the library, of course).

    Best regards, Andreas