-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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.GetProperties(object instance) is not thread-safe #92394
Comments
Tagging subscribers to this area: @dotnet/area-system-componentmodel Issue DetailsDescriptionIf multiple threads call TypeDescriptor.GetProperties(object instance) at the same time, they can get different results if the instance has a TypeDescriptorProvider attribute. I believe this is because of missing locks around reading the WeakHashTables. Reproduction Steps
|
Verified repro; the threads after the first do not call |
The minimal "simple" lock I found is in the method of I believe the reason is:
I have tested the modified code with more concurrent threads and find no deadlocks. |
to wrong results when many methods are called simultaneously. The PR fixes that by extending the lock statement. Fix dotnet#92394
We are working around this by calling TypeDescriptor.GetProvider(type) for every type that has a TypeProviderAttribute. We do this at application startup before we do any parallel queries for it. |
Note there is a newer PR for this now: #92521 |
This long-standing threading issues in TypeDescriptor have been addressed in .NET 9 Preview 1, so any existing work-arounds can be removed. Workarounds included pre-populating internal caches such as by calling Also see Concurrency issue in TypeDescriptor.GetConverter(type). The threading issues also exist in .NET Framework. If you are affected by this issue in .NET Framework, please add feedback here so we can determine the priority of porting the fix to .NET Framework. |
Description
If multiple threads call TypeDescriptor.GetProperties(object instance) at the same time, they can get different results if the instance has a TypeDescriptorProvider attribute. I believe this is because of missing locks around reading the WeakHashTables.
Reproduction Steps
The text was updated successfully, but these errors were encountered: