Bug 6095 - Flawed BlockingCollection(T).TakeFromAny Implementation - Only Blocks On First Collection
Summary: Flawed BlockingCollection(T).TakeFromAny Implementation - Only Blocks On Firs...
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Jérémie Laval
Depends on:
Reported: 2012-07-12 11:42 UTC by dave
Modified: 2013-09-12 16:44 UTC (History)
6 users (show)

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

Runnable reproduce scenario (1.42 MB, application/octet-stream)
2013-09-11 09:14 UTC, Gabriël van der Kruijk

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:

Description dave 2012-07-12 11:42:48 UTC
BlockingCollection(T).TakeFromAny is supposed to block until ANY of the BlockingCollections in the collections parameter receives an item. However, in the Mono implementation, the code only blocks on the FIRST collection in the collections parameter. If an item is added to one of the other collections, the TakeFromAny call does not catch it and the block is never released.

The relevant code is:

foreach (var coll in collections)
 try {
  item = coll.Take (cancellationToken); // Only checks the FIRST collection!!
  return index;
 } catch {}

Not sure what a good fix would be - perhaps a loop that does a TryTake on each collection until an item is available?
Comment 1 Rodrigo Kumpera 2013-01-09 16:04:13 UTC
Jeremie, can you take a look on this one?
Comment 2 Miguel de Icaza [MSFT] 2013-01-10 09:11:23 UTC
Adding Marek and Martin, since Jeremie is out this week.
Comment 3 Gabriël van der Kruijk 2013-09-11 09:13:50 UTC
This bug still exists in Xamarin.iOS 6.4. 

I will also post an attachment with a runnable reproduction of the issue.
Comment 4 Gabriël van der Kruijk 2013-09-11 09:14:52 UTC
Created attachment 4833 [details]
Runnable reproduce scenario
Comment 5 Rodrigo Kumpera 2013-09-12 16:44:53 UTC
Fixed in mono/master. This commit did lost the current release train, so it will take a bit longer to have it.

Desktop mono 3.2.4 will have it.