环境:
.NET Core 3.1
Linux + Docker
问题:
近期发布后发现,服务经常需要多次重启才能启动。观察日志发现异常:
Unhandled exception. 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.
尝试网上很多方法后,还是出现了问题,通过断点发现 Configuration 的 ReloadOnChange 不管怎么样都是 true,后面通过如下方法解决了
webBuilder.ConfigureAppConfiguration((hostingContext, config) => { IHostEnvironment env = hostingContext.HostingEnvironment;
//调用Clear 会报错,因时间就没有深查了 config.Sources.ForEach(source => { if (source is JsonConfigurationSource) { var jsonConfigurationSource = (JsonConfigurationSource)source; jsonConfigurationSource.ReloadOnChange = false; } }); config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false); if (env.IsDevelopment() && !string.IsNullOrEmpty(env.ApplicationName)) { var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName)); if (appAssembly != null) { config.AddUserSecrets(appAssembly, optional: true); } } config.AddEnvironmentVariables(); if (args != null) { config.AddCommandLine(args); } }).UseStartup<Startup>();