[Info] InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct #26868
Milestone
Just raising this so people will find the issue in a search.
This is an intentional new exception that is being thrown by the Dictionary in newer .NET Core (issue https://github.com/dotnet/corefx/issues/28123, PR dotnet/coreclr#16991) which indicates the dictionary is being incorrectly modified concurrently by multiple threads (it wouldn't have been detected previously and could lead to infinite loops, or incorrect data returned)
Also applies now to HashSets (issue https://github.com/dotnet/corefx/issues/28209, PR dotnet/corefx#28225)
Dictionary
andHashSet
are not safe for concurrent readers and writers. Dictionaries/Hashsets that are not written to after set-up are safe for concurrent readers. They are never safe for a write and any other operation (read or write).They either need:
ConcurrentDictionary
ImmutableDictionary
,ImmutableHashSet
or copy dict, add to new copyInterlocked.CompareExchange
on reference with new dict (returned from Add for immutable, or copy for Dict) with added itemCompareExchange
fails do re-copy + add (go to ii.)/cc @danmosemsft @vancem @jkotas @stephentoub
Issues are being filed upstream IdentityServer/IdentityServer4#2453 and dotnet/efcore#12713 and dotnet/efcore#12713 (comment)
The text was updated successfully, but these errors were encountered: