Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/LaunchDarkly.OpenFeature.ServerProvider/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using LaunchDarkly.Logging;
using LaunchDarkly.Sdk;
using LaunchDarkly.Sdk.Internal.Concurrent;
using LaunchDarkly.Sdk.Server;
using LaunchDarkly.Sdk.Server.Interfaces;
using OpenFeature;
Expand Down Expand Up @@ -32,7 +31,8 @@ public sealed partial class Provider : FeatureProvider
private readonly EvalContextConverter _contextConverter;
private readonly StatusProvider _statusProvider;

private readonly AtomicBoolean _initializeCalled = new AtomicBoolean(false);
private readonly object _initLock = new object();
private bool _initializeCalled = false;

// There is no support for void task completion, so we use bool as a dummy result type.
private readonly TaskCompletionSource<bool> _initCompletion = new TaskCompletionSource<bool>();
Expand Down Expand Up @@ -130,9 +130,13 @@ public override Task<ResolutionDetails<Value>> ResolveStructureValueAsync(string
/// <inheritdoc />
public override Task InitializeAsync(EvaluationContext context, CancellationToken cancellationToken = default)
{
if (_initializeCalled.GetAndSet(true))
lock (_initLock)
{
return _initCompletion.Task;
if (_initializeCalled)
{
return _initCompletion.Task;
}
_initializeCalled = true;
}

_client.FlagTracker.FlagChanged += FlagChangeHandler;
Expand Down