launchdarkly / dotnet-client-sdk

LaunchDarkly Client-side SDK for .NET
Other
7 stars 10 forks source link

FlagValueChanged not firing on first event if AutoEnvAttributes is enabled #70

Closed jbrookssmokeball closed 3 months ago

jbrookssmokeball commented 8 months ago

Description The FlagValueChanged event does not fire on the first event after initializing if AutoEnvAttributes is enabled.

To reproduce Use the following code to initialize LdClient with AutoEnvAttributes enabled: (update YOUR_USER_ID with any LD user's ID and YOUR_KEY with your SDK key).

var builder = Context
    .Builder(ContextKind.Default, "YOUR_USER_ID");

var context = builder.Build();

var configuration = Configuration
    .Builder("YOUR_KEY", ConfigurationBuilder.AutoEnvAttributes.Enabled)
    .Build();

var ldClient = LdClient.Init(
    configuration,
    context,
    TimeSpan.FromSeconds(30));

ldClient.FlagTracker.FlagValueChanged += NotifyFlagValueChanged;

The NotifyFlagValueChanged function looks like:

private void NotifyFlagValueChanged(object sender, FlagValueChangeEvent e)
{
    Console.WriteLine($"Received change: {e.Key} from {e.OldValue} to {e.NewValue}");
}

Run the code and make a change to a flag on LaunchDarkly that will change the evaluated value for the user.

Expected behavior The flag change event is received by the client side code.

Actual behavior The first flag change event is not received by the client side code. Subsequent flag change events are received by the client side code.

SDK version LaunchDarkly.ClientSdk 4.0.0

Language version, developer tools C#

OS/platform Windows 11, .NET 6

Additional context If AutoEnvAttributes is disabled, then this works as expected. Unable to reproduce on LaunchDarkly.ClientSdk 3.1.0.

tanderson-ld commented 8 months ago

Thank you for bringing this to our attention. I will investigate and respond once completed.

tanderson-ld commented 3 months ago

Logged as SC-246089

tanderson-ld commented 3 months ago

@jbrookssmokeball , I have been able to reproduce the issue and am investigating the root cause now.

tanderson-ld commented 3 months ago

We have opened a PR for the fix and should have that released in the next day or two. PR is here.

tanderson-ld commented 3 months ago

Version 5.2.1 has been released with the fix. Thank you for your help!