-
Notifications
You must be signed in to change notification settings - Fork 150
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
Nats.Client can't connect to IPv6 server on .net core < 3.0 #272
Comments
Does the following work on 2.2? var ipAddresses = Dns.GetHostAddresses(s.url.Host);
if (ipAddresses?.Length == 0)
{
throw new NATSConnectionException($"Could not resolve host {s.url.Host}");
}
client = new TcpClient();
var task = client.ConnectAsync(ipAddresses, s.url.Port); This would use all available IP Addresses for the connection. I don't believe that
It does look like it could return an empty array if only IPv6 addresses were available on an IPv4 only machine. |
No, it doesn't. To get it work we still need to specify family address var ipAddresses = Dns.GetHostAddresses(s.url.Host);
if (ipAddresses.Length == 0)
{
throw new NATSConnectionException($"Could not resolve host {s.url.Host}");
}
var ipV4only = ipAddresses.All(addr => addr.AddressFamily == AddressFamily.InterNetwork);
client = new TcpClient(ipV4only ? AddressFamily.InterNetwork : AddressFamily.InterNetworkV6);
var task = client.ConnectAsync(ipAddresses, s.url.Port); |
Thank you for looking into this, much appreciated. The option above looks feasible. I'm also wondering if we should stick to whatever the .NET framework defaults to, but add an option to override the AddressFamily. |
I'm unable to get the fix working unfortunately, hung up on possibly a toolchain issue, but I'm not sure: dotnet/standard#1431 |
After Windows 10 KB4512508, the client cannot connect to nats server with default options, using .Net core 2.2. It was working before the update and suddenly not able to connect to nats://localhost:4222 |
This is no good. imo, there are a few options until the issue is resolved in .NET core... There is the simple way to expose an option to override the default address family. Likely only InterNetwork and InterNetworkV6 will work, but we never know what could be coming up in the future. A drawback is that it will require code changes. If the default fails, we could keep trying to connect looping through the address families. e.g: The DNS option looks ok, but imo seems fragile (not because of the code), but because it's DNS. |
Looks like because we reference .NET Standard 1.3 and not something later like 1.6, we can't use the non-async versions: dotnet/standard#1431 (comment)
|
We should be referencing |
You're correct, it is the System.Net.NameResolution which references 1.3. So we would need to reference netstandard2.0 in order to use |
We are in the process of making updates that will put us in position to workaround whatever changed in .NET. Please be patient... |
Hello. I'm facing problem with connecting to nats server via ipv6.
it crashes with exception
As i understand, problem is here - https://github.com/nats-io/nats.net/blob/master/NATS.Client/Conn.cs#L427. By default TCPClient created with AddressFamily.InterNetwork which is IPv4 only. If i change this line to
than it can connect to ipv6 nats without problem.
More interestingly, everything works fine without any modifications on .net core 3.0, cause of this pr - dotnet/corefx#30036.
But i think it should be fixed for 2.2 also. Best way to do it and stay compatible with 3.0 changes is to resolve ip address before tcpclient creation. Something like that:
This way it works for ipv4 and ipv6 on both .net core 2.2 and 3.0. If this is correct approach - i can make pr.
The text was updated successfully, but these errors were encountered: