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

File watcher polling env setting not defined - File Watcher does not work in K8S #3546

Closed
grahambunce opened this issue Mar 8, 2022 · 3 comments

Comments

@grahambunce
Copy link

grahambunce commented Mar 8, 2022

Describe the Bug

Using the mcr.microsoft.com/dotnet/aspnet:6.0-alpine in a K8S environment with the configuration JSON file watcher, changes to config maps are not detected.

This then appears that .net is not picking up changes that K8S has itself detected.

See dotnet/runtime#36091 and dotnet/runtime#64222 for details.

The fix is to include
ENV DOTNET_USE_POLLING_FILE_WATCHER=true

in the build process that creates the docker image. I have been asked on dotnet/runtime#64222 to raise this as an issue against the docker image.

Steps to Reproduce

  1. Create an application that uses a config mapped file for configuration that detects changes, e.g.
        private static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureAppConfiguration((hostingContext, config) =>
                {
                    config.AddJsonFile(Path.Combine(AppContext.BaseDirectory, "servicemap", "ServiceRouting.json"), false, true);
                })
                .ConfigureWebHostDefaults(wb =>
                {
                    wb.UseStartup<Startup>();
                });
    }

Snip -> (code in an API Controller)

        private readonly IOptionsMonitor<ServiceRouting> _configuration;

        public OperationsController(IOptionsMonitor<ServiceRouting> configuration)
        {
            _configuration = configuration;
            _configuration.OnChange((sr) =>
            {
                Console.WriteLine("configuration change detected at " + DateTime.Now);
            });

The file is a config map in K8S
2. Run the container in K8S
3. Change the config map.

K8S will eventually detect the change but .net will not. Expected behaviour is that .net will also detect the change.

The fix is to include DOTNET_USE_POLLING_FILE_WATCHER=true in the container.

The assumption is that this should be set by default and not need an additional step for the container to work correctly in K8S

@mthalman
Copy link
Member

mthalman commented Mar 9, 2022

[Triage] It seems reasonable to add this environment variable for aspnet images assuming that there's no overhead that would negatively impact scenarios that don't require the file watcher. @davidfowl - Can you comment on whether setting DOTNET_USE_POLLING_FILE_WATCHER=true by default for all aspnet containers would be the right thing to do?

Given that the addition of explicitly setting this environment variable would be a breaking change, this would be a change that would only be considered for the upcoming .NET 7 release.

@jkotalik
Copy link

jkotalik commented Apr 6, 2022

I hit something similar in dotnet/runtime#64222

@mthalman
Copy link
Member

mthalman commented Jun 7, 2022

After further discussion, we won't be setting this variable in the Dockerfile. It will be up to the users of this container image to set the variable in their own Dockerfile to opt into this behavior. There is currently discussion around alternative solutions besides explicitly setting the DOTNET_USE_POLLING_FILE_WATCHER variable. If anything concrete happens with that, I'll update this issue to link to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants