You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Accessing Socket.LocalEndpoint throws ArgumentException after connect
AddressFamily: Unspecified
Connected to: Unspecified/localhost:55644
System.ArgumentException: The AddressFamily InterNetworkV6 is not valid for the System.Net.IPEndPoint end point, use InterNetwork instead. (Parameter 'socketAddress')
at System.Net.Sockets.IPEndPointExtensions.Create(EndPoint thisObj, SocketAddress socketAddress) in System.Net.Sockets.dll:token 0x6000414+0x8d
at System.Net.Sockets.Socket.get_LocalEndPoint() in System.Net.Sockets.dll:token 0x60001cf+0x0
This happens when localhost points to IPv6 address ::1
jose@m1 % cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
#127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
Works fine when I just have the 127.0.0.1 localhost entry, it used to work with .NET 5
My code is something like
await _socket.ConnectAsync(_addr, cancel).ConfigureAwait(false);
Console.WriteLine($"Connected to: {_addr}");
var localEndpoint = _socket.LocalEndPoint; // Throws
jose@m1 icerpc-csharp % dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.100-preview.4.21255.9
Commit: 950e4949a7
Runtime Environment:
OS Name: Mac OS X
OS Version: 11.4
OS Platform: Darwin
RID: osx.11.0-arm64
Base Path: /usr/local/share/dotnet/sdk/6.0.100-preview.4.21255.9/
I will try to create a minimal project to repro, as I got this with a large project when moving to .NET 6 preview 4
Also got similar failures with .NET6 preview4 on Ubuntu
Activity
geoffkizer commentedon May 29, 2021
Are you using a dual mode socket?
Exact repro code would be helpful.
wfurt commentedon May 31, 2021
and basic info about product and OS used.
pepone commentedon May 31, 2021
I will try to create a minimal project to repro, as I got this with a large project when moving to .NET 6 preview 4
Also got similar failures with .NET6 preview4 on Ubuntu
wfurt commentedon May 31, 2021
The
AddressFamily: Unspecifiedis certainly suspicious. If this is regression to 5, it should not be difficult to find.pepone commentedon May 31, 2021
I have created a test case to reproduce the issue see https://github.com/pepone/socket-test
Note this only fails when localhost has both entries in
/etc/hostsas mentioned earlierwfurt commentedon May 31, 2021
I have repro on Ubuntu @pepone and I verified it is regression from 5.0
tmds commentedon Jun 1, 2021
I took a look at what happens here.
An attempt is made against the IPv6 address using an
IPEndPoint.This
IPEndPointgets stored in the Socket as the_rightEndPoint.The connect fails.
Then this endpoint is mutated to point to the IPv4 address.
Now the connect is successful.
When
LocalEndPointis retrieved,_rightEndPointis not of the right address family: it should be IPv6 (mapped IPv4), but it is IPv4.@wfurt you can assign this to me. I'll look at providing a fix.