Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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

Closed
benaadams opened this issue Jul 19, 2018 · 6 comments
Milestone

Comments

@benaadams
Copy link
Member

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 and HashSet 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:

  1. Single threaded access
  2. Use under lock
  3. Change to a ConcurrentDictionary
  4. Or use immutable approach:
    1. Change to ImmutableDictionary, ImmutableHashSet or copy dict, add to new copy
    2. Interlocked.CompareExchange on reference with new dict (returned from Add for immutable, or copy for Dict) with added item
    3. If CompareExchange 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)

@terrajobst
Copy link
Member

Presumably this was filed as closed to have a central place?

@benaadams
Copy link
Member Author

Presumably this was filed as closed to have a central place?

Yes so it can be found via search using the exception message (as the issue and PR don't directly quote it)

@8vishal
Copy link

8vishal commented Oct 9, 2020

Its seems thread communication between MVC n core...

@8vishal
Copy link

8vishal commented Oct 9, 2020

Need to go back to basic sta or mta

@8vishal
Copy link

8vishal commented Oct 9, 2020

I am no sure but if u v findings pls post.

@8vishal
Copy link

8vishal commented Oct 9, 2020

Cons: No Solution: or Remdies for business: Restart IIS.
Let Business go to sky high.

@dotnet dotnet locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants