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

UseAzureAppConfiguration and AzureAppConfigurationRefreshMiddleware break context execution #915

Open
fjbelizon opened this issue May 10, 2024 · 13 comments
Assignees
Labels
.NET Config Provider Issues related to the AppConfig .NET Core configuration provider. question

Comments

@fjbelizon
Copy link

I have detected that if we make use of ‘UseAzureAppConfiguration’, which in turn internally injects the middleware ‘AzureAppConfigurationRefreshMiddleware’, it breaks the execution of the context of the Eternal Orchestration Functions.

I am using Azure Isolated Function in NET 8, using package ‘Microsoft.Azure.AppConfiguration.Functions.Worker’ in version 7.2.0.

The middleware internally performs an ‘ExecutionContext.SuppressFlow()’, which breaks the execution flow of the context: https://learn.microsoft.com/en-us/dotnet/api/system.threading.executioncontext.suppressflow?view=net-8.0

Right now the solution I am applying is to use ‘AddAzureAppConfiguration’ without ‘UseAzureAppConfiguration’. In my orchestrator constructor I inject ‘IConfigurationRefresherProvider’ to use the configuration refresher in the orchestrator activities.

The problem is not described anywhere and should be checked. Thanks in advance.

@zhenlan zhenlan added .NET Config Provider Issues related to the AppConfig .NET Core configuration provider. question labels May 10, 2024
@amerjusupovic
Copy link
Member

Hi @fjbelizon, we got a similar issue about durable functions being broken a while back, but ExecutionContext.SuppressFlow() wasn't mentioned. In the discussion there as well as in the linked issue that's in the Azure Functions repo, it was thought that the problem was not specific to the Azure App Configuration middleware.

One helpful test would be to see if version 6.0.1 of the provider also causes this issue for you, since that was before we added the call to SuppressFlow(). If the issue goes away, I'll need to update that original issue. Thanks!

@fjbelizon
Copy link
Author

Hi @amerjusupovic. Ok, I'm going to do the test

@fjbelizon
Copy link
Author

@amerjusupovic yes, same problem. Version 6.0.1 also breaks the execution of Eternal Functions.

I attach the code sample for you to test: bug-azure-app-configuration-refresh-middleware.zip. I've put two ‘TODO’ tags for you to comment/uncomment the lines that make the execution work/fail.

I look forward to your review. Thanks in advance.

@sparraguerra
Copy link

Any news about this issue? Thanks in advance

@jimmyca15
Copy link
Member

@amerjusupovic

Given there was a repro with 6.0.1 do you believe it would be the same issue as here?

@amerjusupovic

This comment was marked as outdated.

@fjbelizon
Copy link
Author

Ok, thanks @amerjusupovic 👌

@jimmyca15
Copy link
Member

This looks like a dupe of this issue. I don't think ExecutionContext.SuppressFlow has any involvement here. This supported by 6.0.1 reproing as well.

@jimmyca15
Copy link
Member

jimmyca15 commented May 31, 2024

@amerjusupovic if you can confirm this is a dupe of the aforementioned issue we should merge this issue into the existing one which the Functions team mentioned they need to solve on their end.

@amerjusupovic
Copy link
Member

Sorry for the confusion in my previous response, yes the repro in 6.0.1 suggests it's the same issue, and that was before the call to SuppressFlow was added. This should be merged with the existing one.

@BrunoCandia
Copy link

BrunoCandia commented Jul 2, 2024

is there any news about this issue? or any alternative, thanks in advance!!

@ivankaurov
Copy link

@BrunoCandia we're using the BackgroundService that is thechnically doing the same stuff

internal sealed class AzureAppConfigRefreshService : BackgroundService
{
    private readonly IEnumerable<IConfigurationRefresher> _refreshers;

    public AzureAppConfigRefreshService(IConfigurationRefresherProvider refresherProvider)
    {
        _refreshers = refresherProvider.Refreshers;
    }

    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    {
        while (!stoppingToken.IsCancellationRequested)
        {
            try
            {
                foreach (var refresher in _refreshers)
                {
                    await refresher.TryRefreshAsync(stoppingToken);
                }

                await Task.Delay(...);
            }
            catch (OperationCanceledException) when (stoppingToken.IsCancellationRequested)
            {
                _logger.LogInformation("AzureAppConfig has been stopped");
                break;
            }
        }
    }
}
// ...
// serviceCollection.AddHostedService<AzureAppConfigRefreshService>();

@ivankaurov
Copy link

@amerjusupovic @jimmyca15 are there any news on this issue? We're still using our in-house kludge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Config Provider Issues related to the AppConfig .NET Core configuration provider. question
Projects
None yet
Development

No branches or pull requests

7 participants