-
Notifications
You must be signed in to change notification settings - Fork 25.1k
edit asp0028 /1 #34095
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
Merged
Merged
edit asp0028 /1 #34095
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
147383b
edit asp0028 /1
Rick-Anderson 5368acd
Update aspnetcore/fundamentals/static-files/samples/9.x/StaticFilesSa…
Rick-Anderson e781c9b
edit asp0028 /1
Rick-Anderson 17268a4
edit asp0028 /1
Rick-Anderson 4e15fe5
edit asp0028 /1
Rick-Anderson f5b40ca
edit asp0028 /1
Rick-Anderson 9e94dc0
Apply suggestions from code review
Rick-Anderson 155f7a5
react to feedback
Rick-Anderson cfd6fb1
Merge branch 'asp026/ra/1' of https://github.com/dotnet/AspNetCore.Do…
Rick-Anderson 0b1c252
react to feedback
Rick-Anderson 48acce2
react to feedback
Rick-Anderson 75d8ba0
Apply suggestions from code review
Rick-Anderson c58c8cc
Update aspnetcore/diagnostics/asp0028.md
Rick-Anderson 6c863b6
react to feedback
Rick-Anderson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,17 @@ uid: diagnostics/asp0028 | |
|
|
||
| ## Cause | ||
|
|
||
| On the server machine that supports IPv6, listening to `Any`, rather than `IPv6Any` will either not work or be slower than necessary, because of the [underlying System types implementation](https://github.com/dotnet/runtime/issues/82404). | ||
| [IPv6Any](/dotnet/api/system.net.ipaddress.ipv6any) is preferred to [Any](/dotnet/api/system.net.ipaddress.any) because `Any` is less performant than `IPv6Any`. In some cases, `Any` may not work at all. `Any` has performance problems due to the [underlying System types implementation](https://github.com/dotnet/runtime/issues/82404). | ||
|
||
|
|
||
| At the moment of current article publishing, in case of HTTP/1.x or HTTP/2.0 a name like `localhost` will resolve to `[::1]`, which won't be accepted by the server, forcing a retry with `127.0.0.1` (i.e. failed attempt before each connection). | ||
| `127.0.0.1` is the IPv4 loopback address. `::1` is the IPv6 loopback address. `Any` is the wildcard address for IPv4. `IPv6Any` is the wildcard address for IPv6. | ||
|
|
||
Rick-Anderson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Current behavior with with IPv6 when using HTTP/1.x or HTTP/2.0: | ||
|
|
||
| * `localhost` resolves to `[::1]`. | ||
| * `[::1]` isn't accepted by the server, which forces a retry using `127.0.0.1`, creating a repeated cycle. | ||
|
|
||
| Using `Any` with the preceding conditions reports the `ASP0028` diagnostic message: | ||
Rick-Anderson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This usage will be reported with a diagnostic message: | ||
| ```csharp | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
|
|
@@ -31,36 +37,32 @@ This usage will be reported with a diagnostic message: | |
|
|
||
| ## Rule description | ||
|
|
||
| The recommended way is to setup Kestrel to listen on `IPv6Any`. | ||
| The recommended way to configure Kestrel to listen for incoming connections on all available `IPv6` network interfaces is with `IPv6Any`. | ||
|
|
||
| ## How to fix violations | ||
|
|
||
| For the reported code | ||
| ```csharp | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
| options.Listen(IPAddress.Any, ...); | ||
| }) | ||
| ``` | ||
| For the problematic code, replace `Any` with `IPv6Any`: | ||
Rick-Anderson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| One can either explicitly change usage to `IPv6Any`: | ||
| ```csharp | ||
| ```diff | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
| options.Listen(IPAddress.IPv6Any, ...); | ||
| - options.Listen(IPAddress.Any, ...); | ||
| + options.Listen(IPAddress.IPv6Any, ...); | ||
| }) | ||
| ``` | ||
|
|
||
| or use another invocation - `options.ListenAnyIP()` without specifying any argument explicitly: | ||
| ```csharp | ||
| Alternatively, use the [ListenAnyIP](https://source.dot.net/#Microsoft.AspNetCore.Server.Kestrel.Core/KestrelServerOptions.cs,1c84a7db2c1f6892) method without specifying any arguments: | ||
Rick-Anderson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```diff | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
| options.ListenAnyIP(...); | ||
| - options.Listen(IPAddress.Any, ...); | ||
| + options.ListenAnyIP(...); | ||
| }) | ||
| ``` | ||
|
|
||
| ## When to suppress warnings | ||
|
|
||
| The severity level of this diagnostic is Information. You can suppress warnings if your intention is to disable `IPv6` usage completely on the server. | ||
| The `ASP0028` diagnostic has [Information](/dotnet/api/microsoft.extensions.logging.loglevel) level severity. Suppress this warning if your intention is to disable `IPv6` usage completely on the server, although doing so risks the performance problems mentioned in this article. | ||
|
|
||
| You can disable IPv6 either system-wide, or for .NET only via the [AppCtx switch or environment variable](https://devblogs.microsoft.com/dotnet/dotnet-6-networking-improvements/#an-option-to-globally-disable-ipv6) | ||
| `IPv6` can be disabled either system-wide, or for .NET only via the [AppCtx switch or environment variable](https://devblogs.microsoft.com/dotnet/dotnet-6-networking-improvements/#an-option-to-globally-disable-ipv6) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
phrasing
has performance problemsis not what I wanted to say - it raises a question of why not fix the System types then? I wanted to avoid thisUh oh!
There was an error while loading. Please reload this page.
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've reverted to your wording with my wording. I don't see the difference between slower than necessary and less performant.