-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Bug]: InvalidCastException
when multiple threads retrieve pipeline
#2412
Comments
If this isn't exactly the same issue as I referenced in the linked discussion, then it's a new different issue that needs to be opened against dotnet/runtime. If you can repro it without Polly even being involved, then it's not an issue in our code, and not something we can reasonably work around either. |
If you read the linked issue, you'll see that the runtime maintainers are choosing not to implement thread safety, which makes it the burden on this library not to invoke Validator from multiple threads. |
The issue I linked from the discussion was to do with thread safety and validation attributes, and was marked as resolved by the poster, hence I assumed that it was either the same, or if it wasn't that it would still be their bug to fix if not (the issue I linked to was fixed). If that's not the case and it's something we need to do something about, then we'll happily accept a pull request if you'd like to address it if you'd like to expedite a fix. |
The fix you are referring to is for .NET source generated options validation (using |
Describe the bug
System.ComponentModel.DataAnnotations.RangeAttribute
is not thread safe.ValidationHelper
does not synchronize access to Validator and is invoked when initializing pipelines. This can lead to occasionalInvalidCastException
when multiple threads retrieve a pipeline for the first time (whileRangeAttribute
is uninitialized).This was previously reported as #2096 but not fixed.
Expected behavior
No exception is thrown.
Actual behavior
No response
Steps to reproduce
It's pretty difficult to reproduce in the registry, due to the specificity of the race condition and the fact that you only get one chance per process to trigger it.
You can simulate it reliably using just the attribute, however.
Example: "25 exceptions encountered (0.0250%)"
Exception(s) (if any)
Polly version
8.5.0
.NET Version
net9.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: