Skip to content

Conversation

@pavelsavara
Copy link
Member

Contributes to dotnet/runtime#122435

@pavelsavara pavelsavara added this to the 10.0.x milestone Dec 11, 2025
@pavelsavara pavelsavara self-assigned this Dec 11, 2025
@github-actions github-actions bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Dec 11, 2025
@pavelsavara pavelsavara modified the milestones: 10.0.x, 11.0-preview1 Dec 11, 2025
@pavelsavara
Copy link
Member Author

Alternatively we can also/instead just change

if (ip.Address.Equals(IPAddress.IPv6Any))

            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))

@pavelsavara pavelsavara marked this pull request as ready for review December 11, 2025 14:55
Copilot AI review requested due to automatic review settings December 11, 2025 14:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AnyIPListenOptions constructor to check IPv6 support before choosing the IP address type
  • Added test coverage for non-IPv6 environments using RemoteExecutor
  • Added Microsoft.DotNet.RemoteExecutor package 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

@pavelsavara
Copy link
Member Author

image

@pavelsavara pavelsavara merged commit e5a3d79 into dotnet:main Dec 15, 2025
30 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-kestrel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants