-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make KestrelConfigurationLoader.Load safe to re-call #48137
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
Changes from 2 commits
8feb8e1
ee1feca
8cccd00
64a2ca6
d1970ae
aff0268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||||
| using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; | ||||||
| using Microsoft.AspNetCore.Server.Kestrel.Https; | ||||||
| using Microsoft.Extensions.Configuration; | ||||||
| using Microsoft.Extensions.Primitives; | ||||||
|
|
||||||
| namespace Microsoft.AspNetCore.Server.Kestrel; | ||||||
|
|
||||||
|
|
@@ -18,7 +19,7 @@ public class KestrelConfigurationLoader | |||||
| { | ||||||
| private readonly IHttpsConfigurationService _httpsConfigurationService; | ||||||
|
|
||||||
| private bool _loaded; | ||||||
| private IChangeToken? _reloadToken; | ||||||
|
|
||||||
| internal KestrelConfigurationLoader( | ||||||
| KestrelServerOptions options, | ||||||
|
|
@@ -234,25 +235,27 @@ internal void ApplyHttpsDefaults(HttpsConnectionAdapterOptions httpsOptions) | |||||
| /// </summary> | ||||||
| public void Load() | ||||||
| { | ||||||
| if (_loaded) | ||||||
| if (_reloadToken is null || _reloadToken.HasChanged) | ||||||
| { | ||||||
| // The loader has already been run. | ||||||
| return; | ||||||
| // Will update _reloadToken | ||||||
| _ = Reload(); | ||||||
| } | ||||||
| _loaded = true; | ||||||
|
|
||||||
| Reload(); | ||||||
|
|
||||||
| foreach (var action in EndpointsToAdd) | ||||||
| { | ||||||
| action(); | ||||||
amcasey marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
|
|
||||||
| // If Load is called again, we don't want to rerun these | ||||||
| EndpointsToAdd.Clear(); | ||||||
| } | ||||||
|
|
||||||
| // Adds endpoints from config to KestrelServerOptions.ConfigurationBackedListenOptions and configures some other options. | ||||||
| // Any endpoints that were removed from the last time endpoints were loaded are returned. | ||||||
| internal (List<ListenOptions>, List<ListenOptions>) Reload() | ||||||
| { | ||||||
| _reloadToken = Configuration.GetReloadToken(); | ||||||
|
||||||
| _reloadToken = Configuration.GetReloadToken(); | |
| _reloadToken = ReloadOnChange ? Configuration.GetReloadToken() : NullChangeToken.Singleton; |
We should not grab the token on load if KestrelConfigurationLoader.ReloadOnChange is false. That's what the is DoesNotReloadOnConfigurationChangeByDefault test is about. Normally it's true if you have a "default" host like WebApplication.
You'll need to add using Microsoft.Extensions.FileProviders too. Not the best namespace there.
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.
I didn't change the existing IChangeToken handling, so I believe that test is still passing. I intentionally decoupled rebind-on-change from determine-if-reloading-would-be-redundant, but I'm open to discussion.
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.
Why am I pulling in Microsoft.Extensions.FileProviders?
Uh oh!
There was an error while loading. Please reload this page.