-
Notifications
You must be signed in to change notification settings - Fork 761
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
[Host] Allow disabling reloadOnChange for Host's CreateDefaultBuilder #2940
Conversation
src/Hosting/Hosting/src/Host.cs
Outdated
@@ -70,9 +70,11 @@ public static IHostBuilder CreateDefaultBuilder(string[] args) | |||
builder.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
var env = hostingContext.HostingEnvironment; | |||
|
|||
var reloadOnChange = hostingContext.Configuration.GetValue("HOSTBUILDER_CONFIG_RELOAD", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The host uses top level keys like contentRoot
.
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.1#contentrootpath
configReload
should be adequate here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there some prefix I can add to that to disambiguate? I was trying to follow the {ASPNETCORE/DOTNET}_FEATURE_DESCRIPTION
nomenclature of other aspnetcore and dotnet flags sort of like DOTNET_USE_POLLING_FILE_WATCHER
This would mean that DOTNET_CONFIGRELOAD
specified in an environment variable would trip the behavior added in this PR, and that to me sounds like it's entirely disabling config reloading, which is not quite the case, as one's own calls to AddJsonFile
are left alone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can at least use the hierarchical config pattern.
Also, config keys are not case sensitive. Changed for readability.
var reloadOnChange = hostingContext.Configuration.GetValue("HOSTBUILDER_CONFIG_RELOAD", true); | |
var reloadFlagConfig = new Dictionary<string, string>() {{ "hostbuilder:configreload", "false" }}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, this has been updated in my most recent commit de16b88
…d of runtime default.
src/Hosting/Hosting/src/Host.cs
Outdated
@@ -70,9 +70,11 @@ public static IHostBuilder CreateDefaultBuilder(string[] args) | |||
builder.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
var env = hostingContext.HostingEnvironment; | |||
|
|||
var reloadOnChange = hostingContext.Configuration.GetValue("HOSTBUILDER_CONFIG_RELOAD", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can at least use the hierarchical config pattern.
Also, config keys are not case sensitive. Changed for readability.
var reloadOnChange = hostingContext.Configuration.GetValue("HOSTBUILDER_CONFIG_RELOAD", true); | |
var reloadFlagConfig = new Dictionary<string, string>() {{ "hostbuilder:configreload", "false" }}; |
…o be longer and cancel using the reload token.
Sorry it took a while to get back around to this one, and thanks for the feedback. I pushed de16b88 to resolve (I think) any dangling parts from the conversations. Changelist
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shirhatti can you sanity check this for usability? CreateDefaultBuilder reads an entry "hostbuilder:configreload" from host config to enable/disable reload for appsettings.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok to me. I’ll leave it to @Tratcher to approve though.
Hello @Tratcher! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
Thanks @kjerk |
Thanks everybody. |
…dotnet/extensions#2940) * Add environment var to allow disabling live reload in default builder * Switch to using hostingContext, rename flag to fit nomenclature. * Change flag to memory data source. Change content root default instead of runtime default. * Update config key to be hierarchical. Change await on positive case to be longer and cancel using the reload token. * Uncomment a development test case. * Apply suggestions from code review Co-authored-by: Chris Ross <Tratcher@Outlook.com> Commit migrated from dotnet/extensions@64140f9
…dotnet/extensions#2940) * Add environment var to allow disabling live reload in default builder * Switch to using hostingContext, rename flag to fit nomenclature. * Change flag to memory data source. Change content root default instead of runtime default. * Update config key to be hierarchical. Change await on positive case to be longer and cancel using the reload token. * Uncomment a development test case. * Apply suggestions from code review Co-authored-by: Chris Ross <Tratcher@Outlook.com> Commit migrated from dotnet/extensions@64140f9
The name of this configuration entry isn't ideal. Maybe it should be host and not hostbuilder? |
@@ -70,9 +70,11 @@ public static IHostBuilder CreateDefaultBuilder(string[] args) | |||
builder.ConfigureAppConfiguration((hostingContext, config) => | |||
{ | |||
var env = hostingContext.HostingEnvironment; | |||
|
|||
var reloadOnChange = hostingContext.Configuration.GetValue("hostBuilder:reloadConfigOnChange", defaultValue: true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also be set to https://github.com/dotnet/runtime/blob/79ae74f5ca5c8a6fe3a48935e85bd7374959c570/src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/FileConfigurationSource.cs#L33?
Apparently this condition is true: https://github.com/dotnet/runtime/blob/79ae74f5ca5c8a6fe3a48935e85bd7374959c570/src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/FileConfigurationProvider.cs#L34 even with "hostBuilder": {"reloadConfigOnChange": false }
in appsettings.json.
kernel implementation without inotify support throw the following exception on application startup and there seems to be no way to turn (this quite an unimportant) feature off:
Unhandled exception. System.IO.IOException: Function not implemented
at System.IO.FileSystemWatcher.StartRaisingEvents()
at System.IO.FileSystemWatcher.StartRaisingEventsIfNotDisposed()
at System.IO.FileSystemWatcher.set_EnableRaisingEvents(Boolean value)
at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.TryEnableFileSystemWatcher()
at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.CreateFileChangeToken(String filter)
at Microsoft.Extensions.FileProviders.PhysicalFileProvider.Watch(String filter)
at Microsoft.Extensions.Configuration.FileConfigurationProvider.<.ctor>b__1_0()
at Microsoft.Extensions.Primitives.ChangeToken.OnChange(Func`1 changeTokenProducer, Action changeTokenConsumer)
at Microsoft.Extensions.Configuration.FileConfigurationProvider..ctor(FileConfigurationSource source)
at Microsoft.Extensions.Configuration.Json.JsonConfigurationSource.Build(IConfigurationBuilder builder)
at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build()
at Microsoft.Extensions.Hosting.HostBuilder.BuildAppConfiguration()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at mymvc1.Program.Main(String[] args)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got the global opt-out knob working with: dotnet/runtime@457ed11; DOTNET_USE_POLLING_FILE_WATCHER=1
in unikernel environment completely disables inotify. sadly, it wasn't backported to net5 so i switched to net6..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for HostBuilder, at the time this was being changed if you used CreateDefaultBuilder() you were getting live reloading whether you wanted it or not because it was hard coded to true
If Source.ReloadOnChange is populated by an env var and is available by the time ConfigureAppConfiguration() fires then that would work a bit better.
What did we merge here? Did we change the key to host vs hostBuilder? |
Looking back at this it looks like the config change was mentioned a few months after it was merged/closed (Mar 19). I think iirc at the time when referencing the docs, while Host.blah was used as a static factory method, most things were referencing IHostBuilder, CreateHostBuilder, CreateDefaultBuilder, etc etc, and the only other ENV var override I could find referenced the implementation class, so I just defaulted to hostBuilder, though host is a bit nicer and agnostic sounding. To make the change would require subsequent changes and maybe another PR? Also because I myself had trouble finding the tiny link at the top of this PR, the original issue this is resolving is here: #2939 which gives some details on what problem this was addressing. |
was ASPNETCORE_BUILDER_CONFIG_RELOAD used, i can't find any reference to it through google, or was this solved some totally different way? |
https://github.com/dotnet/runtime/blob/02ad981eab46339b6abef5b97b3db761d22b6455/src/libraries/Microsoft.Extensions.Hosting/src/HostingHostBuilderExtensions.cs#L237 |
Addresses #2939