Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IFeatureManager.IsAnabledAsync() doesn't get fresh information from IConfiguration in ASP.NET Framework #134

Open
ios29A opened this issue Aug 2, 2021 · 3 comments

Comments

@ios29A
Copy link

ios29A commented Aug 2, 2021

Hello !

I have a problem in ASP.NET Framework WebForms application, there IFeatureManager.IsAnabledAsync() always returns cached data, but not fresh from IConfiguration, however in test console app for .NET Framework it works well.
Both projects use .NET Framework 4.8

I've found that, ConfigurationFeatureDefinitionProvider.cs#31 ChangeTokenConsumer delegate never called after refresher.TryRefreshAsync() or RefershAsync() is executed, but under debug I can see that IConfiguration is updated with new data.
P.S. For now I have quick solution - I just reset ConfigurationFeatureDefinitionProvider._stale flag manually by using reflection, and it works, but it's very bad idea, so I need a better solution.

Any ideas why this happening ?
Thanks for the help !

@jimmyca15
Copy link
Member

Hello @ios29A do you have a small example/repro of how you are consuming the library to help diagnose any issues?

ChangeTokenConsumer delegate never called after refresher.TryRefreshAsync() or RefershAsync() is executed

If that is the case, then it could be the reason for seeing stale data. If you have more details on this as well that would be helpful. I am not aware of any bugs in the configuration reload pipeline on any .NET frameworks.

@ios29A
Copy link
Author

ios29A commented Aug 3, 2021

Hi !
Yes, actually it's almost full copy of .NET Framework sample for dynamic poll
https://docs.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-dotnet,
What I have in global.asax.cs now:

		private IFeatureManager _featureManager = null;
		private IConfigurationRefresher _refresher = null;
		private IServiceCollection _services = null;

		private void SetupFeatureFlags() {
			IConfigurationRoot configuration = new ConfigurationBuilder()
				.AddAzureAppConfiguration(options =>
				{
					options.Connect(System.Configuration.ConfigurationManager.AppSettings["FeatureFlagsConnectionString"])
						.UseFeatureFlags(featureFlagOptions =>
						{
							featureFlagOptions.CacheExpirationInterval =
								TimeSpan.FromSeconds(
									int.TryParse(System.Configuration.ConfigurationManager.AppSettings["FeatureFlagsCacheExpirationSeconds"], out var seconds) ? seconds : 20
								);
						});
					_refresher = options.GetRefresher();
				}).Build();

			_services = new ServiceCollection();

			_services.AddSingleton<IConfiguration>(configuration)
				.AddFeatureManagement()
				.AddFeatureFilter<TargetingFilter>()
				.AddFeatureFilter<TimeWindowFilter>()
				.AddFeatureFilter<PercentageFilter>();
			_services.AddSingleton<ITargetingContextAccessor, TargetingContextAccessor>();

			using (ServiceProvider serviceProvider = _services.BuildServiceProvider()) {
				_featureManager = serviceProvider.GetRequiredService<IFeatureManager>();
			}
		}

		public bool IsFeatureEnabled(string feature) {
			_refresher.TryRefreshAsync().GetAwaiter().GetResult();

			// hack to reset cache, TODO: must be removed after proper solution
			new PrivateObject(_featureManager, "_featureDefinitionProvider").SetField("_stale", 1); 
			return _featureManager.IsEnabledAsync(feature).GetAwaiter().GetResult();
		}

If that is the case, then it could be the reason for seeing stale data.

If I don't set _stale manually it's always 0, moreover I've set breakpoint on ChangeTokenConsumer delegate, and it's called in console app .NET Framework, but not in ASP.NET

@zhiyuanliang-ms
Copy link
Contributor

Hi, @ios29A

Is this issue still existing?

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

No branches or pull requests

3 participants