Skip to content

Commit

Permalink
Fix Validator concurrency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcclellan committed Dec 31, 2024
1 parent 3b6f7c6 commit 37071b2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Polly.Core/ResiliencePipelineBuilderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace Polly;
public abstract class ResiliencePipelineBuilderBase
#pragma warning restore S1694 // An abstract class should have both abstract and concrete methods
{
// Workaround for https://github.com/dotnet/runtime/issues/110917
private static readonly object ValidatorLock = new();

private readonly List<Entry> _entries = [];
private bool _used;

Expand Down Expand Up @@ -105,7 +108,14 @@ internal void AddPipelineComponent(Func<StrategyBuilderContext, PipelineComponen
Guard.NotNull(factory);
Guard.NotNull(options);

Validator(new ResilienceValidationContext(options, $"The '{TypeNameFormatter.Format(options.GetType())}' are invalid."));
var validationContext = new ResilienceValidationContext(
options,
$"The '{TypeNameFormatter.Format(options.GetType())}' are invalid.");

lock (ValidatorLock)
{
Validator(validationContext);
}

if (_used)
{
Expand Down

0 comments on commit 37071b2

Please sign in to comment.