Bug 18616 - Parallel.ForEach not updating ConcurrentDictionary
Summary: Parallel.ForEach not updating ConcurrentDictionary
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 3.0.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-03-27 13:16 UTC by Eric Roller
Modified: 2014-07-29 18:49 UTC (History)
2 users (show)

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


Attachments
Test program that runs multiple loops in parallel with each loop using Parallel.ForEach to insert a single item into a ConcurrentDictionary (3.43 KB, text/plain)
2014-03-27 13:16 UTC, Eric Roller
Details
Launches 100 TPLBug.exe processes in series to determine the frequency of failure (1.73 KB, text/plain)
2014-03-27 13:18 UTC, Eric Roller
Details


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 Eric Roller 2014-03-27 13:16:10 UTC
Created attachment 6423 [details]
Test program that runs multiple loops in parallel with each loop using Parallel.ForEach to insert a single item into a ConcurrentDictionary

Description of Problem:
I am using Parallel.ForEach to add a single item to a ConcurrentDictionary. Occasionally, the ConcurrentDictionary will not be updated after the call to Parallel.ForEach. The frequency of this error depends on the specific hardware. I have seen anywhere from 10% to 75% of these tests fail.

The TPLBug.cs test launches many tests in parallel to tax the CPU so that this bug is more likely to be triggered. 
I have created a ProcessWrappper.cs file that launches the test program (TPLBug.exe) multiple times in series to evaluate the frequency of the failure.

The test program is in TPLBug.cs 


Steps to reproduce the problem:
1. Download ProcessWrappper.cs and TPLBug.cs
2. compile source (mcs TPLBug.cs; mcs ProcessWrappper.cs)
3. Make sure mono is in your PATH and run mono ProcessWrappper.exe or just run mono TPLBug.exe multiple times until the error is triggered


Actual Results:
...
ConcurrentDictionary missing items during attempt 2/10 and concurrent loop 14/20!
Test report: failed to add item to dictionary 1 times out of 200
Round 98 failed
ConcurrentDictionary missing items during attempt 1/10 and concurrent loop 1/20!
Test report: failed to add item to dictionary 1 times out of 200
Round 100 failed
Test failed! Failure rate 75.0% 75/100



Expected Results:
Test passed!


How often does this happen? 
-10%-75% of runs of TPLBug.exe fail running on linux under mono 3.2.8
-never fails running on linux under mono 2.10.9
-never fails on .NET
Comment 1 Eric Roller 2014-03-27 13:18:05 UTC
Created attachment 6424 [details]
Launches 100 TPLBug.exe processes in series to determine the frequency of failure

Uploading wrapper to launches 100 TPLBug.exe processes in series to determine the frequency of failure.
Comment 2 Eric Roller 2014-04-13 01:11:23 UTC
I tried locking on a regular (i.e. non-concurrent) Dictionary and it resulted in the program hanging. This indicates the bug is likely in the Thread Parallel Library implementation and not ConcurrentDictionary.
Comment 3 Eric Roller 2014-07-29 18:49:10 UTC
I tested this bug in a new mono version (3.6.1) and was not able to reproduce it. Marking this as resolved.