-
Notifications
You must be signed in to change notification settings - Fork 2k
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
ObserverManager: fix Collection was modified #8707
base: main
Are you sure you want to change the base?
Conversation
This is an expensive approach. I wonder if we can come up with a cheaper one, possibly at the expense of complexity |
Using |
maybe https://learn.microsoft.com/en-us/dotnet/api/system.collections.frozen.frozenset?view=net-8.0 is good option here? |
we need some BenchmarkDotNet tests to check performance. Apparently, we can use |
I think it's not that easy to come up with a benchmark as relationship beetween amount of reads and writes would change the result. Speaking about complexity: it might be efficient to cache ToList result and invalidate that cache whenever any writes to the dictionary are applied. BUT It would be nice to commit any fix for the error if finding out the fastest solution is not that easy. Any fix is better than current (throwing exceptions) code. |
This is still occurring in Orleans v8.1 |
Benchmark, copying the observers vs
|
If you add a subscription while
Notify
is in process of enumerating the observers it can lead to exception:System.InvalidOperationException Collection was modified; enumeration operation may not execute.
This problem was also mentioned here #8284 (comment) in 3rd paragraph
This can be checked with a simple unit test (without grains):
I did not add this to the current tests, since we don't really have any dedicated
ObserverManager
tests and it's unclear in what namespace to add it.I'm not fan that we are creating a new list, but this is the simplest way to fix it, I guess.
Microsoft Reviewers: Open in CodeFlow