Bug 43447 - SynchronizedCollection.Add throws an ArgumentOutOfRangeException
Summary: SynchronizedCollection.Add throws an ArgumentOutOfRangeException
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 4.4.1 (C7SR0)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-08-17 01:30 UTC by Ryan Twitchell
Modified: 2017-09-06 16:55 UTC (History)
1 user (show)

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


Attachments
Example code that produces this bug (897 bytes, text/x-csharp)
2016-08-17 01:30 UTC, Ryan Twitchell
Details

Description Ryan Twitchell 2016-08-17 01:30:57 UTC
Created attachment 17068 [details]
Example code that produces this bug

During concurrent calls to Add and Remove on a SynchronizedCollection instance, Add throws an ArgumentOutOfRangeException with the message "Index must be within the bounds of the List. Parameter name: index".

This was with mono 4.4.1 originally, and a quick check of the code on your github master branch (https://github.com/mono/mono/blob/master/mcs/class/System.ServiceModel/System.Collections.Generic/SynchronizedCollection.cs) shows that this may be because Add reads its backing list's count outside of a lock, and passes that to InsertItem.

Example code attached.  Reproduces almost every run with mono, never with .NET 4.6.

Note You need to log in before you can comment on or make changes to this bug.