Skip to content

Comments

Fix session manager bug#581

Open
zhiyuanliang-ms wants to merge 3 commits intomainfrom
zhiyuanliang/fix-session-manager
Open

Fix session manager bug#581
zhiyuanliang-ms wants to merge 3 commits intomainfrom
zhiyuanliang/fix-session-manager

Conversation

@zhiyuanliang-ms
Copy link
Member

Why this PR?

#580

break;
}
}
}
Copy link

@apetukhov apetukhov Feb 16, 2026

Choose a reason for hiding this comment

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

I also think that if there is no value in the session manager, then it should be written to what the feature manager returns, i.e. the default value.

foreach (ISessionManager sessionManager in _sessionManagers)
{
await sessionManager.SetAsync(feature, enabled).ConfigureAwait(false);
}

Copy link
Member Author

Choose a reason for hiding this comment

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

The current logic is that if feature definition is not null, then feature manager will do the feature evaluation and the result will be set to session manager.

Did I miss something?

Choose a reason for hiding this comment

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

It doesn't matter whether a feature definition exists; if the feature manager returns a result and doesn't throw an exception, the same result must be set in the session manager.

Test case

  1. Check the boolean feature x in the feature manager.
  2. There is no definition for feature x.
  3. There is no previously saved result in the session manager.
  4. The default result "false" stored in the session manager
  5. The feature manager returns the default result "false"

Step 4 is currently missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

It doesn't matter whether a feature definition exists; if the feature manager returns a result and doesn't throw an exception, the same result must be set in the session manager.

I believe this is the current behavior (when feature definition is not null).

We introduced the bug in v4. The bug is when feature definition is null, the result won't be set to session manage, I explained it in this comment

Choose a reason for hiding this comment

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

[Fact]
        public async Task SetResultInSessionManagerWhenFeatureDefinitionIsNull()
        {
            IConfiguration config = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

            var services = new ServiceCollection();

            ISessionManager sessionManager = new TestSessionManager();

            services
                .AddSingleton(config)
                .AddSingleton<ISessionManager>(sessionManager)
                .AddFeatureManagement();

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            IFeatureManager featureManager = serviceProvider.GetRequiredService<IFeatureManager>();

           // session manager is clean here
            var result = await featureManager.IsEnabledAsync("UnexistedFeature");

           // session manager should store the result after evaluation
             Assert.AreEqual(result, await sessionManager.GetAsync("UnexistedFeature"));
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Updated. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants