Skip to content

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

@daxian-dbw daxian-dbw requested a review from PaulHigin as a code owner April 8, 2023 05:09
@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