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

TypeDescriptor.Refresh is not thread-safe #51618

Closed
stephentoub opened this issue Apr 21, 2021 · 3 comments · Fixed by #51621
Closed

TypeDescriptor.Refresh is not thread-safe #51618

stephentoub opened this issue Apr 21, 2021 · 3 comments · Fixed by #51621

Comments

@stephentoub
Copy link
Member

stephentoub commented Apr 21, 2021

In general, static methods are supposed to be thread-safe, and there's no warning in the docs about it not being so.

But TypeDescriptor.Refresh may end up calling into ReflectTypeDescriptionProvider.GetPopulatedTypes. It does so while holding a lock GetPopulatedTypes enumerates the _typeData Hashtable. If a concurrent call to GetTypeData (which takes a different lock) mutates that hashtable, it invalidates the enumerator being used by GetPopulatedTypes, causing GetPopulatedTypes to throw an exception.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Apr 21, 2021
@ghost
Copy link

ghost commented Apr 21, 2021

Tagging subscribers to this area: @safern
See info in area-owners.md if you want to be subscribed.

Issue Details

In general, static methods are supposed to be thread-safe, and there's no warning in the docs about it not being so.

But TypeDescriptor.Refresh may end up calling into ReflectTypeDescriptionProvider.GetPopulatedTypes. It does so while holding a lock But GetPopulatedTypes takes a different lock, and enumerates the _typeData Hashtable. If a concurrent call to GetTypeData adds to that Hashtable, it invalidates the enumerator being used by GetPopulatedTypes, causing GetPopulatedTypes to throw an exception.

Author: stephentoub
Assignees: -
Labels:

area-System.ComponentModel, untriaged

Milestone: -

@FilipToth
Copy link
Contributor

I don't understand why this method is static in the first place. Does it update the cache for all instances of the TypeDescriptor class?

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Apr 21, 2021
@safern safern removed the untriaged New issue has not been triaged by the area owner label Apr 21, 2021
@safern safern added this to the 6.0.0 milestone Apr 21, 2021
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Apr 21, 2021
@ghost ghost locked as resolved and limited conversation to collaborators May 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants