-
Notifications
You must be signed in to change notification settings - Fork 10.9k
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 3 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.
|
||||||
| } | ||||||
|
|
||||||
| // 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(); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should not grab the token on load if You'll need to add using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't change the existing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why am I pulling in |
||||||
|
|
||||||
| var endpointsToStop = Options.ConfigurationBackedListenOptions.ToList(); | ||||||
| var endpointsToStart = new List<ListenOptions>(); | ||||||
| var endpointsToReuse = new List<ListenOptions>(); | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.