-
Notifications
You must be signed in to change notification settings - Fork 25.1k
feat: ASP0028 diagnostic docs #34084
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
DeagleGross
merged 1 commit into
dotnet:main
from
DeagleGross:dmkorolev/diagnostics/aspnet0028
Nov 12, 2024
Merged
Changes from all commits
Commits
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 |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| --- | ||
| title: "ASP0028: ## Analyzer to suggest using IPAddress.IPv6Any instead of IPAddress.Any if applicable" | ||
| ms.date: 11/11/2024 | ||
| description: "Learn about analysis rule ASP0028: Consider using IPAddress.IPv6Any instead of IPAddress.Any" | ||
| author: deaglegross | ||
| monikerRange: '>= aspnetcore-10.0' | ||
| ms.author: deaglegross | ||
| uid: diagnostics/asp0028 | ||
| --- | ||
| # ASP0028: Consider using `IPAddress.IPv6Any` instead of `IPAddress.Any` | ||
|
|
||
| | | Value | | ||
| | - | - | | ||
| | **Rule ID** | ASP0028 | | ||
| | **Category** | Usage | | ||
| | **Fix is breaking or non-breaking** | Non-breaking | | ||
|
|
||
| ## 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). | ||
|
|
||
| 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). | ||
|
|
||
| This usage will be reported with a diagnostic message: | ||
| ```csharp | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
| options.Listen(IPAddress.Any, ...); | ||
| }) | ||
| ``` | ||
|
|
||
| ## Rule description | ||
|
|
||
| The recommended way is to setup Kestrel to listen on `IPv6Any`. | ||
|
|
||
| ## How to fix violations | ||
|
|
||
| For the reported code | ||
| ```csharp | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
| options.Listen(IPAddress.Any, ...); | ||
| }) | ||
| ``` | ||
|
|
||
| One can either explicitly change usage to `IPv6Any`: | ||
| ```csharp | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
| options.Listen(IPAddress.IPv6Any, ...); | ||
| }) | ||
| ``` | ||
|
|
||
| or use another invocation - `options.ListenAnyIP()` without specifying any argument explicitly: | ||
| ```csharp | ||
| .UseKestrel().ConfigureKestrel(options => | ||
| { | ||
| 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. | ||
|
|
||
| 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) | ||
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.
Uh 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.
Rule description
The recommended way to configure Kestrel to listen for incoming connections on all available
IPv6network interfaces is withIPv6Any.How to fix violations
For the problematic code, replace
AnywithIPv6Any:.UseKestrel().ConfigureKestrel(options => { - options.Listen(IPAddress.Any, ...); + options.Listen(IPAddress.IPv6Any, ...); })Alternatively, use the
ListenAnyIPmethod without specifying any argument:.UseKestrel().ConfigureKestrel(options => { - options.Listen(IPAddress.Any, ...); + options.ListenAnyIP(...); })When to suppress warnings
The
ASP0028diagnostic has a Information level severity. Suppress warnings if your intention is to disableIPv6usage completely on the server, although this comes with the risk of the performance problems mentions in this articleIPv6can be disabled either system-wide, or for .NET only via the AppCtx switch or environment variable