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

Synchronize access to System.ComponentModel.DataAnnotations.Validator #2428

Merged
merged 6 commits into from
Jan 13, 2025

Conversation

kmcclellan
Copy link
Contributor

Pull Request

The issue or feature being addressed

[Bug]: InvalidCastException when multiple threads retrieve pipeline

Details on the issue fix or feature implementation

.NET team has targeted a fix in v10 of the runtime. In the meantime, I've opted for a simple workaround that synchronizes validation calls for all strategy options models (these are the only ones that use RangeAttribute). Given this only occurs when a pipeline is first built, I don't feel like we need to be concerned about contention.

Confirm the following

  • I started this PR by branching from the head of the default branch
  • I have targeted the PR to merge into the default branch
  • I have included unit tests for the issue/feature
  • I have successfully run a local build

@kmcclellan
Copy link
Contributor Author

@dotnet-policy-service agree

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.39%. Comparing base (c66d8ca) to head (6f0fe50).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2428   +/-   ##
=======================================
  Coverage   85.39%   85.39%           
=======================================
  Files         312      312           
  Lines        7464     7464           
  Branches     1121     1121           
=======================================
  Hits         6374     6374           
  Misses        905      905           
  Partials      185      185           
Flag Coverage Δ
linux 85.36% <ø> (-0.03%) ⬇️
macos 85.36% <ø> (-0.03%) ⬇️
windows 85.36% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to quantify what, if any, impact this has on performance by running the benchmarks before and after the change to see if there's any impact from introducing the lock (I'd hope not as it's on construction not execution).

test/Polly.Core.Tests/ResiliencePipelineBuilderTests.cs Outdated Show resolved Hide resolved
src/Polly.Core/ResiliencePipelineBuilderBase.cs Outdated Show resolved Hide resolved
@martincostello martincostello added this to the v8.5.1 milestone Jan 11, 2025
martincostello added a commit to martincostello/Polly that referenced this pull request Jan 11, 2025
Apply changes from App-vNext#2428.
@martincostello
Copy link
Member

I ran the benchmarks for main and then this PR on my laptop to get a consistent baseline to compare (diff) and as expected there's no discernible difference, it's just noise.

Once some CI-related infrastructure changes are sorted out and merged, then I'll merge this 👍

@martincostello
Copy link
Member

That change has been made now - you just need to rebase/merge with main.

@martincostello
Copy link
Member

Sorry, #2443 is also needed (which this PR flushed out).

@martincostello martincostello merged commit f982bb6 into App-vNext:main Jan 13, 2025
24 checks passed
Copy link
Contributor

Thanks for your contribution @kmcclellan - the changes from this pull request have been published as part of version 8.5.1 📦, which is now available from NuGet.org 🚀

@@ -7,6 +7,9 @@ namespace Polly.Utils;
[ExcludeFromCodeCoverage]
internal static class ValidationHelper
{
// Workaround for https://github.com/dotnet/runtime/issues/110917
private static readonly object ValidatorLock = new();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use the Backport of the new System.Threading.Lock in a future update?

@kmcclellan kmcclellan deleted the validator-locking branch January 14, 2025 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants