Re-wrote .ToObservableChangeSet() operators for both Cache and List, to eliminate a deadlocking issue. #1017
+3,381
−2,300
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #998.
The essential premise for the changes here is to extract
IScheduler.Schedule()calls out of the main operator logic, specifically out of the umbrella of anylock. Because we're invoking these schedulers recursively (we form a loop by having each scheduled action finish by re-scheduling itself), and some of the core schedulers are not fully-asynchronous (including our default scheduler,TaskPoolScheduler), anylocking that we do can conflict withlocking being done internally within the scheduler.In order to accomplish this refactoring, I deemed it prudent to simplify the operators and all the custom changeset assembly they were doing, to instead just use
ChangeAwareList<>andChangeAwareCache<>. The operators are MUCH more readable now, I think, and seem to have no significant change in performance, despite all the effort I put into optimizing them last time around.We don't have a ready-to-go benchmark for the list version, but we do for the cache version:
I also had to come up with a way to manage test parallelization, since I have tests that are time-sensitive, to try and detect deadlocks, and they were failing due to thread/task starvation, when running in parallel with the rest of the test suite. Unfortunately, controlling parallelism within xUnit not straightforward. I think the pattern I came up with makes sense, but I plan to look into upgrading to xUnit v3 in the near future, and I that may render this setup obsolete.