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

Avoid concurrency issues with dictionaries #1450

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

drewnoakes
Copy link
Member

@drewnoakes drewnoakes commented Dec 18, 2023

Fixes #1239

Background processes can trigger concurrent modifications of collections being queried or enumerated, which can lead to corruptions and exceptions or runaway CPU.

Use ConcurrentDictionary<,> instead to prevent these issues.

Also:

  • Add explicit string comparer for comparing resource names.
  • Use consistent name for these collections.
  • Add some debug assertions as validation of incoming data.

Future work might pull this pattern out into a new class, potentially also using a lighter collection than ConcurrentDictionary<,>. I'll wait until the current client/server refactoring is complete before doing that.

Microsoft Reviewers: Open in CodeFlow

Background processes can trigger conccurent modifications of collections being queried or enumerated, which can lead to corruptions and exceptions or runaway CPU.

Use `ConcurrentDictionary<,>` instead to prevent these issues.

Also:

- Add explicit string comparer for comparing resource names.
- Use consistent name for these collections.
- Add some debug assertions as validation of incoming data.

Future work might pull this pattern out into a new class, potentially also using a lighter collection than `ConcurrentDictionary<,>`. I'll wait until the current client/server refactoring is complete before doing that.
@drewnoakes drewnoakes merged commit bede210 into dotnet:main Dec 18, 2023
8 checks passed
@drewnoakes drewnoakes deleted the fix-concurrency branch December 18, 2023 02:39
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential CollectionModifiedException in ConsoleLogs and Resources pages
2 participants