Bug 13092 - Take on a BlockingCollection initialized with contents blocks indefinitely
Summary: Take on a BlockingCollection initialized with contents blocks indefinitely
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-07-08 06:50 UTC by Weeble
Modified: 2015-03-17 02:43 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Weeble 2013-07-08 06:50:15 UTC
If you initialize a BlockingCollection with a non-empty IProducerConsumerCollection, then attempt to read from the collection, it will block indefinitely.

Example code:

using System.Collections.Concurrent;

class Test
{
    static void Main()
    {
        var array = new[] { 123 };
        var queue = new ConcurrentQueue<int>(array);
        var blockingCollection = new BlockingCollection<int>(queue);
        int result = blockingCollection.Take();
        System.Console.WriteLine(result);
    }
}

Under .NET, this outputs "123" and exits. Under Mono 3.0.12 on Linux, this hangs indefinitely.

In general, it appears that if the collection is initialized with N items, it's never possible to remove an item if that would reduce its size below N. It looks like the BlockingCollection's internal record of how many items are in the collection is never initialized correctly.
Comment 1 Marek Safar 2015-03-17 02:43:08 UTC
Fixed in mono 4.0