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

Fix race condition in Add-Type #19471

Merged
merged 2 commits into from
Apr 13, 2023
Merged

Conversation

daxian-dbw
Copy link
Member

PR Summary

Fix #19470

Add-Type uses static HashSet and Dictionary for caching type names and assemblies, which are not thread-safe. When running Add-Type with the same C# code from multiple Runspaces simultaneously, these caches may be accessed at the same time, and that will cause a race condition.

The fix is to use ConcurrentDictionary for both caches.

PR Checklist

@ghost ghost assigned iSazonov Apr 8, 2023
@daxian-dbw daxian-dbw assigned daxian-dbw and unassigned iSazonov Apr 8, 2023
@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 8, 2023
Copy link
Collaborator

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@daxian-dbw daxian-dbw merged commit 8ed8b52 into PowerShell:master Apr 13, 2023
@daxian-dbw daxian-dbw deleted the addtype branch April 13, 2023 04:41
@ghost
Copy link

ghost commented Apr 20, 2023

🎉v7.4.0-preview.3 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add-Type fails sporadically with "An item with the same key has already been added"
3 participants