BufferBlock deadlock with OutputAvailableAsync after TryReceiveAll

前端 未结 2 1839
闹比i
闹比i 2021-01-31 18:29

While working on an answer to this question, I wrote this snippet:

var buffer = new BufferBlock();
var producer = Task.Run(async () =>
{
    whi         


        
      
      
      
2条回答
  •  無奈伤痛
    2021-01-31 19:31

    This is a bug in SourceCore being used internally by BufferBlock. Its TryReceiveAll method doesn't turn on the _enableOffering boolean data member while TryReceive does. That results in the task returned from OutputAvailableAsync never completing.

    Here's a minimal reproduce:

    var buffer = new BufferBlock();
    buffer.Post(null);
    
    IList items;
    buffer.TryReceiveAll(out items);
    
    var outputAvailableAsync = buffer.OutputAvailableAsync();
    buffer.Post(null);
    
    await outputAvailableAsync; // Never completes
    
    
    

    I've just fixed it in the .Net core repository with this pull request. Hopefully the fix finds itself in the nuget package soon.

    提交回复
    热议问题