Don't bind to IPv6 when the OS doesn't support it#64734
Merged
pavelsavara merged 2 commits intodotnet:mainfrom Dec 15, 2025
Merged
Don't bind to IPv6 when the OS doesn't support it#64734pavelsavara merged 2 commits intodotnet:mainfrom
pavelsavara merged 2 commits intodotnet:mainfrom
Conversation
Member
Author
|
Alternatively we can also/instead just change case IPEndPoint ip:
listenSocket = new Socket(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
// Kestrel expects IPv6Any to bind to both IPv6 and IPv4
- if (ip.Address.Equals(IPAddress.IPv6Any))
+ if (Socket.OSSupportsIPv6 && ip.Address.Equals(IPAddress.IPv6Any))
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses the issue of Kestrel attempting to bind to IPv6 addresses on systems that don't support IPv6. The change proactively checks Socket.OSSupportsIPv6 before attempting to bind, avoiding unnecessary binding failures and the associated fallback mechanism.
Key Changes:
- Modified
AnyIPListenOptionsconstructor to check IPv6 support before choosing the IP address type - Added test coverage for non-IPv6 environments using
RemoteExecutor - Added
Microsoft.DotNet.RemoteExecutorpackage reference for testing
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Servers/Kestrel/Core/src/AnyIPListenOptions.cs |
Updated constructor to check Socket.OSSupportsIPv6 and use IPAddress.Any when IPv6 is not supported, otherwise use IPAddress.IPv6Any |
src/Servers/Kestrel/Core/test/AddressBinderTests.cs |
Added new test ParseAddressOnOSWithoutIPv6 using RemoteExecutor to verify behavior on systems without IPv6 support |
src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj |
Added reference to Microsoft.DotNet.RemoteExecutor package for testing |
Member
Author
BrennanConroy
approved these changes
Dec 15, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Contributes to dotnet/runtime#122435