-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Comments
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. |
Tagging subscribers to this area: @safern Issue DetailsIn 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.
|
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? |
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.
The text was updated successfully, but these errors were encountered: