Skip to content

[BUG] Providing a Policy Name Selector which returns null causes an infinite loop #543

@kylejuliandev

Description

@kylejuliandev

Observed behavior

If you use the OpenFeature Dependency Injection to setup a Policy, and you fail to specify a name in DefaultNameSelector function, the application will hang while infinitely trying to resolve IFeatureClient.

Expected Behavior

Specifying no name when configuring a DefaultNameSelector should resolve the default IFeatureClient.

Steps to reproduce

If you call AddOpenFeature and specify a Policy Name Selector which returns null, no IFeatureClient can be resolved from the dependency injection scope.

builder.Services.AddOpenFeature(featureBuilder =>
{
    featureBuilder
        .AddHostedFeatureLifecycle()
        .AddInMemoryProvider("InMemory", _ => new Dictionary<string, Flag>()
        {
            {
                "welcome-message", new Flag<bool>(
                    new Dictionary<string, bool> { { "show", true }, { "hide", false } }, "show")
            }
        })
        .AddPolicyName(policy =>
        {
            policy.DefaultNameSelector = provider =>
            {
                return null;
            };
        });
});

I suspect the issue is here:

if (name == null)
{
return provider.GetRequiredService<IFeatureClient>();
}

If no name is configured, we attempt to resolve any IFeatureClients already registered. However, this just ends up calling itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions