8000 Fix NullReferenceException in DSC ClearCache() by anmenaga · Pull Request #15373 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fix NullReferenceException in DSC ClearCache() #15373

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

Merged
merged 3 commits into from
May 12, 2021

Conversation

anmenaga
Copy link
@anmenaga anmenaga commented May 10, 2021

PR Summary

In a multi-threaded environment there is a NullReferenceException in DSC ClearCache().
This fix is needed for GuestConfig.

PR Context

Initial values for fields marked with ThreadStaticAttribute should not be used, because such initialization occurs only once, when the class constructor executes, and therefore affects only one thread. Sometimes in a multi-threaded GuestConfig environment this was causing NullReferenceException in ClearCache() methods where the ThreadStatic filed t_currentImportDscResourceInvocations was accessed.

GuestConfig verified this fix on private binaries.

Side note: the entire section of code, where current fix is, will be removed soon by DSC as a subsystem PR.

PR Checklist

@anmenaga anmenaga added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label May 10, 2021
@ghost ghost assigned iSazonov May 10, 2021
@daxian-dbw
Copy link
Member

Good catch, @anmenaga! Quoted from docs:

Do not specify initial values for fields marked with ThreadStaticAttribute, because such initialization occurs only once, when the class constructor executes, and therefore affects only one thread. If you do not specify an initial value, you can rely on the field being initialized to its default value if it is a value type, or to null if it is a reference type.

@anmenaga
Copy link
Author

This is needed for GC release in a couple of days, so merging.

@anmenaga anmenaga merged commit ae77246 into PowerShell:master May 12, 2021
@ghost
Copy link
ghost commented May 27, 2021

🎉v7.2.0-preview.6 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.

3 participants
0