Azure / azure-functions-dotnet-worker

Azure Functions out-of-process .NET language worker
MIT License
431 stars 184 forks source link

dotnet 8 isolated worker does not reload configuration after updating json file #2792

Closed ben-ward1 closed 2 days ago

ben-ward1 commented 3 weeks ago

Description

Posting this here after getting no responses in this discussion.

The json configuration provider in a v4 Azure functions w/ dotnet 8 isolated worker does not reload config values when the json file is changed.

The often cited reloadOnChange: true option when adding a json file for configuration, as seen below, does not seem to be respected.

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureAppConfiguration((hostingContext, config) =>
    {
        config.SetBasePath(Directory.GetCurrentDirectory());

        if (hostingContext.HostingEnvironment.IsDevelopment())
        {
            config.AddJsonFile("local.settings.json", optional: false, reloadOnChange: true);
        }

        config.AddEnvironmentVariables();
    })
    .ConfigureServices((hostingContext, services) =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();

        services.ConfigureAppOptions(hostingContext.Configuration);
    })
    .Build();

host.Run();

This prevents IOptionsMonitor/IOptionsSnapshot from returning up-to-date values for json provided configuration.

I looked through the docs to determine if this is an intended/known limitation for the isolated worker process, but never found anything explicit.

Steps to reproduce

See this repo to reproduce the the current behavior in an azure function app alongside the expected behavior in a web api.

jviau commented 2 days ago

@ben-ward1 local.settings.json is not intended to be loaded through IConfiguration. It is loaded by core tools and the values are supplied as environment variables to both the host and worker process.

Beyond that, we do not own .AddJsonFile or auto reloading of IConfiguration, this issue is better suited for dotnet/runtime repo. If you want config to auto-reload for the worker only, you can use a custom json file (such as appsettings.json)

Closing as this is by design for local.settings.json.