Bug 18182 - ConcurrentQueue<T>.TryPeek() is not thread safe
Summary: ConcurrentQueue<T>.TryPeek() is not thread safe
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-03-05 07:11 UTC by Craig Minihan
Modified: 2014-03-17 13:38 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 Craig Minihan 2014-03-05 07:11:03 UTC
TryPeek() in ConcurrentQueue looks like this:

public bool TryPeek (out T result)
{
	if (IsEmpty) {
		result = default (T);
		return false;
	}
		
	Node first = head.Next;
	result = first.Value;       // *** can exception here ***
	return true;
}

The problem is that between the IsEmpty test and the assignment "result = first.Value" "head.Next" can become null making first == null and causing an exception when it tries to get the field Value from the null instance.

I will fix and create a pull for this issue.
Comment 1 Craig Minihan 2014-03-05 10:39:36 UTC
Fix submitted in Pull #932
Comment 2 Jérémie Laval 2014-03-17 13:38:40 UTC
Fix merged in master