Skip to content

Commit 2683851

Browse files
authored
Document Kestrel runtime config changes breaking change in 5.0 (#18917)
1 parent 4a446fd commit 2683851

File tree

3 files changed

+115
-4
lines changed

3 files changed

+115
-4
lines changed

docs/core/compatibility/3.1-5.0.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Breaking changes, version 3.1 to 5.0
33
description: Lists the breaking changes from version 3.1 to version 5.0 of .NET, ASP.NET Core, and EF Core.
4-
ms.date: 04/29/2020
4+
ms.date: 06/11/2020
55
---
66
# Breaking changes for migration from version 3.1 to 5.0
77

@@ -13,6 +13,7 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v
1313
- [Extensions: Package reference changes affecting some NuGet packages](#extensions-package-reference-changes-affecting-some-nuget-packages)
1414
- [HTTP: HttpClient instances created by IHttpClientFactory log integer status codes](#http-httpclient-instances-created-by-ihttpclientfactory-log-integer-status-codes)
1515
- [HTTP: Kestrel and IIS BadHttpRequestException types marked obsolete and replaced](#http-kestrel-and-iis-badhttprequestexception-types-marked-obsolete-and-replaced)
16+
- [Kestrel: Configuration changes at run time detected by default](#kestrel-configuration-changes-at-run-time-detected-by-default)
1617
- [Localization: "Pubternal" APIs removed](#localization-pubternal-apis-removed)
1718
- [Localization: ResourceManagerWithCultureStringLocalizer class and WithCulture interface member removed](#localization-resourcemanagerwithculturestringlocalizer-class-and-withculture-interface-member-removed)
1819
- [SignalR: MessagePack Hub Protocol moved to MessagePack 2.x package](#signalr-messagepack-hub-protocol-moved-to-messagepack-2x-package)
@@ -36,7 +37,11 @@ If you're migrating from version 3.1 of .NET Core, ASP.NET Core, or EF Core to v
3637

3738
***
3839

39-
[!INCLUDE [Localization: "Pubternal" APIs removed](~/includes/core-changes/aspnetcore/5.0/localization-pubternal-apis-removed.md)]
40+
[!INCLUDE[Kestrel: Configuration changes at run time detected by default](~/includes/core-changes/aspnetcore/5.0/kestrel-configuration-changes-at-run-time-detected-by-default.md)]
41+
42+
***
43+
44+
[!INCLUDE[Localization: "Pubternal" APIs removed](~/includes/core-changes/aspnetcore/5.0/localization-pubternal-apis-removed.md)]
4045

4146
***
4247

docs/core/compatibility/aspnetcore.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: ASP.NET Core breaking changes
33
titleSuffix: ""
44
description: Lists the breaking changes in ASP.NET Core.
5-
ms.date: 04/29/2020
5+
ms.date: 06/11/2020
66
author: scottaddie
77
ms.author: scaddie
88
---
@@ -44,6 +44,7 @@ The following breaking changes are documented on this page:
4444
- [Identity: SignInAsync throws exception for unauthenticated identity](#identity-signinasync-throws-exception-for-unauthenticated-identity)
4545
- [Identity: SignInManager constructor accepts new parameter](#identity-signinmanager-constructor-accepts-new-parameter)
4646
- [Identity: UI uses static web assets feature](#identity-ui-uses-static-web-assets-feature)
47+
- [Kestrel: Configuration changes at run time detected by default](#kestrel-configuration-changes-at-run-time-detected-by-default)
4748
- [Kestrel: Connection adapters removed](#kestrel-connection-adapters-removed)
4849
- [Kestrel: Empty HTTPS assembly removed](#kestrel-empty-https-assembly-removed)
4950
- [Kestrel: Request trailer headers moved to new collection](#kestrel-request-trailer-headers-moved-to-new-collection)
@@ -92,7 +93,11 @@ The following breaking changes are documented on this page:
9293

9394
***
9495

95-
[!INCLUDE [Localization: "Pubternal" APIs removed](~/includes/core-changes/aspnetcore/5.0/localization-pubternal-apis-removed.md)]
96+
[!INCLUDE[Kestrel: Configuration changes at run time detected by default](~/includes/core-changes/aspnetcore/5.0/kestrel-configuration-changes-at-run-time-detected-by-default.md)]
97+
98+
***
99+
100+
[!INCLUDE[Localization: "Pubternal" APIs removed](~/includes/core-changes/aspnetcore/5.0/localization-pubternal-apis-removed.md)]
96101

97102
***
98103

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
### Kestrel: Configuration changes at run time detected by default
2+
3+
Kestrel now reacts to changes made to the `Kestrel` section of the project's `IConfiguration` instance (for example, *appsettings.json*) at run time. To learn more about how to configure Kestrel using *appsettings.json*, see the *appsettings.json* example in [Endpoint configuration](/aspnet/core/fundamentals/servers/kestrel#endpoint-configuration).
4+
5+
Kestrel will bind, unbind, and rebind endpoints as necessary to react to these configuration changes.
6+
7+
For discussion, see issue [dotnet/aspnetcore#22807](https://github.com/dotnet/aspnetcore/issues/22807).
8+
9+
#### Version introduced
10+
11+
5.0 Preview 7
12+
13+
#### Old behavior
14+
15+
Before ASP.NET Core 5.0 Preview 6, Kestrel didn't support changing configuration at run time.
16+
17+
In ASP.NET Core 5.0 Preview 6, you could opt into the now-default behavior of reacting to configuration changes at run time. Opting in required binding Kestrel's configuration manually:
18+
19+
```csharp
20+
using Microsoft.AspNetCore.Hosting;
21+
using Microsoft.Extensions.Hosting;
22+
23+
public class Program
24+
{
25+
public static void Main(string[] args) =>
26+
CreateHostBuilder(args).Build().Run();
27+
28+
public static IHostBuilder CreateHostBuilder(string[] args) =>
29+
Host.CreateDefaultBuilder(args)
30+
.ConfigureWebHostDefaults(webBuilder =>
31+
{
32+
webBuilder.UseKestrel((builderContext, kestrelOptions) =>
33+
{
34+
kestrelOptions.Configure(
35+
builderContext.Configuration.GetSection("Kestrel"), reloadOnChange: true);
36+
});
37+
38+
webBuilder.UseStartup<Startup>();
39+
});
40+
}
41+
```
42+
43+
#### New behavior
44+
45+
Kestrel reacts to configuration changes at run time by default. To support that change, <xref:Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults%2A> calls `KestrelServerOptions.Configure(IConfiguration, bool)` with `reloadOnChange: true` by default.
46+
47+
#### Reason for change
48+
49+
The change was made to support endpoint reconfiguration at run time without completely restarting the server. Unlike with a full server restart, unchanged endpoints aren't unbound even temporarily.
50+
51+
#### Recommended action
52+
53+
* For most scenarios in which Kestrel's default configuration section doesn't change at run time, this change has no impact and no action is needed.
54+
* For scenarios in which Kestrel's default configuration section does change at run time and Kestrel should react to it, this is now the default behavior.
55+
* For scenarios in which Kestrel's default configuration section changes at run time and Kestrel shouldn't react to it, you can opt out as follows:
56+
57+
```csharp
58+
using Microsoft.AspNetCore.Hosting;
59+
using Microsoft.Extensions.Hosting;
60+
61+
public class Program
62+
{
63+
public static void Main(string[] args) =>
64+
CreateHostBuilder(args).Build().Run();
65+
66+
public static IHostBuilder CreateHostBuilder(string[] args) =>
67+
Host.CreateDefaultBuilder(args)
68+
.ConfigureWebHostDefaults(webBuilder =>
69+
{
70+
webBuilder.UseKestrel((builderContext, kestrelOptions) =>
71+
{
72+
kestrelOptions.Configure(
73+
builderContext.Configuration.GetSection("Kestrel"), reloadOnChange: false);
74+
});
75+
76+
webBuilder.UseStartup<Startup>();
77+
});
78+
}
79+
```
80+
81+
**Notes:**
82+
83+
This change doesn't modify the behavior of the `KestrelServerOptions.Configure(IConfiguration)` overload, which still defaults to the `reloadOnChange: false` behavior.
84+
85+
It's also important to make sure the configuration source supports reloading. For JSON sources, reloading is configured by calling `AddJsonFile(path, reloadOnChange: true)`. Reloading is already configured by default for *appsettings.json* and *appsettings.{Environment}.json*.
86+
87+
#### Category
88+
89+
ASP.NET Core
90+
91+
#### Affected APIs
92+
93+
<xref:Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults%2A?displayProperty=nameWithType>
94+
95+
<!--
96+
97+
#### Affected APIs
98+
99+
`Overload:Microsoft.Extensions.Hosting.GenericHostBuilderExtensions.ConfigureWebHostDefaults`
100+
101+
-->

0 commit comments

Comments
 (0)