Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix race condition in Add-Type#19471

Merged
daxian-dbw merged 2 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
daxian-dbw:addtypedaxian-dbw/PowerShell:addtypeCopy head branch name to clipboard
Apr 13, 2023
Merged

Fix race condition in Add-Type#19471
daxian-dbw merged 2 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
daxian-dbw:addtypedaxian-dbw/PowerShell:addtypeCopy head branch name to clipboard

Conversation

@daxian-dbw

Copy link
Copy Markdown
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

@SeeminglyScience SeeminglyScience left a comment

Copy link
Copy Markdown
Contributor

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

ghost commented Apr 20, 2023

Copy link
Copy Markdown

🎉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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.