Thanks to visit codestin.com
Credit goes to github.com

Skip to content

disable FileWatching for FileVersionProvider/Default IFileProvider #42070

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

Open
1 task done
schmitch opened this issue Jun 7, 2022 · 5 comments
Open
1 task done

disable FileWatching for FileVersionProvider/Default IFileProvider #42070

schmitch opened this issue Jun 7, 2022 · 5 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Milestone

Comments

@schmitch
Copy link

schmitch commented Jun 7, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

currently when running production under docker or under kubernetes we sometimes run into:

System.IO.IOException: The configured user limit (128) on the number of inotify instances has been reached, or the per-process limit on the number of open file descriptors has been reached.
    at System.IO.FileSystemWatcher.StartRaisingEvents()
    at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher()
    at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)
    at Microsoft.AspNetCore.Mvc.Razor.Infrastructure.DefaultFileVersionProvider.AddFileVersionToPath(PathString requestPathBase, String path)

the problem is that we use asp-append-version which actually triggers a file watcher, since it calls FileProvider.Watch.

Describe the solution you'd like

However in production this is not really that cool, since it can quickly exhaust all inodes. Thus it would be great if it would be possible to disable the file watching in production completly, the same thing that can be done for configuration files via the following: https://docs.microsoft.com/de-de/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-6.0#disable-app-configuration-reload-on-change

Additional context

No response

@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jun 7, 2022
@schmitch
Copy link
Author

schmitch commented Jun 7, 2022

btw. at the Moment we basically use the following to remove the FileWatcher:

            if (CurrentEnvironment.IsProduction())
            {
                CurrentEnvironment.WebRootFileProvider = new EvFileProvider(CurrentEnvironment.WebRootFileProvider);
            }
            
            // file provider, that delegates to IFileProvider from WebRootFileProvider, except the Watch method:
    public IChangeToken Watch(string filter)
    {
        // we do not want to poll for files in production...
        // never ever!!
        return NullChangeToken.Singleton;
    }

thus it will disable the FileWatching completly, however there is no settings key to manually disable it, which is a little bit strange, since that can be a little bit wierd when running on k8s where the node does not have a high user limit.

@javiercn
Copy link
Member

javiercn commented Jun 7, 2022

@schmitch thanks for contacting us.

We will move this issue to the backlog and consider it for a future release if we see more feedback in this area.

@javiercn javiercn added this to the Backlog milestone Jun 7, 2022
@ghost
Copy link

ghost commented Jun 7, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@mjrousos
Copy link
Member

mjrousos commented Dec 5, 2023

+1. I'm working with a customer who ran into this in a scenario where, in an AKS environment, they had a large blob storage container volume mounted under wwwroot and this behavior causes use of "asp-append-version" to result in a large performance degradation while the FileSystemWatcher walks the mounted blob storage container.

In this case, the file watching wouldn't be an issue if it was limited to the directory the linked file was in instead of all of wwwroot recursively. Updating the FileSystemWatcher usage to be scoped just to the necessary directories would help a lot.

In case it's useful, here's a stack trace of the issue:

00007F7A29FF8580 00007fbafc3c4792 Interop+Sys.ReadDirR(IntPtr, Byte*, Int32, DirectoryEntry*)
00007F7A29FF8630 00007fbb0238271a System.IO.Enumeration.FileSystemEnumerator`1[[System.__Canon, System.Private.CoreLib]].MoveNext() [/_/src/libraries/System.Private.CoreLib/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs @ 110]
00007F7A29FF8A00 00007fbb02387acd System.IO.FileSystemWatcher+RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory, System.String) [/_/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @ 451]
00007F7A29FF8B00 00007fbb023f7336 System.IO.FileSystemWatcher+RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory, System.String) [/_/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @ 453]
00007F7A29FF8C10 00007fbb023f7336 System.IO.FileSystemWatcher+RunningInstance.AddDirectoryWatchUnlocked(WatchedDirectory, System.String) [/_/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @ 453]
00007F7A29FF8D20 00007fbb023f6606 System.IO.FileSystemWatcher.StartRaisingEvents() [/_/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.Linux.cs @ 63]
00007F7A29FF8DA0 00007fbafded4b1f Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher() [/_/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs @ 433]
00007F7A29FF8DD0 00007fbafded3e70 Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(System.String) [/_/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs @ 149]
00007F7A29FF8DF0 00007fbaff6bdb0e Microsoft.AspNetCore.Mvc.Razor.Infrastructure.DefaultFileVersionProvider.AddFileVersionToPath(Microsoft.AspNetCore.Http.PathString, System.String) [/_/src/Mvc/Mvc.Razor/src/Infrastructure/DefaultFileVersionProvider.cs @ 70]
00007F7A29FF8E50 00007fbb005fb321 Microsoft.AspNetCore.Mvc.TagHelpers.LinkTagHelper.Process(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput) [/_/src/Mvc/Mvc.TagHelpers/src/LinkTagHelper.cs @ 288]
00007F7A29FF8ED0 00007fbaffa329c0 Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput) [/_/src/Razor/Razor/src/TagHelpers/TagHelper.cs @ 53]
00007F7A29FF8EE0 00007fbaff1724bf Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext) [/_/src/Razor/Razor.Runtime/src/Runtime/TagHelpers/TagHelperRunner.cs @ 42]

@isaevdan
Copy link

Another scenario where option to disable watch would be helpful is when you mount static folder to Azure Files in AppService and you end up in large amounts of transactions billed to your Storage account.

I will have to use some workaround for this case right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

4 participants