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

DNS lookup of IPv6-only hosts fails #6940

Closed
TekkiWuff opened this Issue Feb 10, 2018 · 4 comments

Comments

@TekkiWuff

TekkiWuff commented Feb 10, 2018

Steps to Reproduce

  1. Ensure you have propper IPv6 connectivity e. g. by opening ipv6.google.com in a browser
  2. Write a simple oneliner C# program to do a DNS lookup
var addresse = Dns.GetHostAddresses("ipv6.google.com");
  1. An exception is thrown

Current Behavior

The DNS lookup does not return any IPv6 addresses and fails with an exception for IPv6-only hosts.

Expected Behavior

The DNS lookup returns all IPv6 addresses associated with the hostname.

On which platforms did you notice this

[ ] macOS
[x] Linux
[ ] Windows

Distributor ID: Ubuntu
Description:    Ubuntu 17.10
Release:        17.10
Codename:       artful

Version Used:

Mono JIT compiler version 5.8.0.108 (tarball Fri Jan 19 18:15:21 UTC 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            sgen (concurrent by default)

Installed from repository as described here http://www.mono-project.com/download/#download-lin

Stacktrace

Unhandled Exception:
System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'ipv6.google.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.hostent_to_IPHostEntry (System.String originalHostName, System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00068] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00027] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00052] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00056] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at IPV6Test.MainClass.Main (System.String[] args) [0x00053] in <7972d22e6aeb495781af83f5a15dede8>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'ipv6.google.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.hostent_to_IPHostEntry (System.String originalHostName, System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00068] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00027] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00052] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00056] in <a63b52a3a7644f60a95b388cb72441c2>:0
  at IPV6Test.MainClass.Main (System.String[] args) [0x00053] in <7972d22e6aeb495781af83f5a15dede8>:0

Further details

The (obsolote) Socket.SupportsIPv6 gets always initialised with false here for the PAL (FEATURE_PAL)

s_SupportsIPv4 = true;
s_SupportsIPv6 = false;

As visible in the Stacktrace, System.Net.Dns.hostent_to_IPHostEntry is called at some point during the execution. It iterates over all addresses and removes IPv6 addresses based on the value of Socket.SupportsIPv6.

#pragma warning disable 618
if( (Socket.SupportsIPv6 && newAddress.AddressFamily == AddressFamily.InterNetworkV6) ||
(Socket.SupportsIPv4 && newAddress.AddressFamily == AddressFamily.InterNetwork) )
addrlist.Add(newAddress);
#pragma warning restore 618

For IPv6-only hosts this results in an empty list which then throws an exception
if(addrlist.Count == 0)
Error_11001 (originalHostName);

Interestingly the not obsolete Socket.OSSupportsIPv6 return true

Setting Socket.SupportsIPv6 to true via reflection fixes the issue. Tested DNS lookups and WebRequests (see example code below)

I'm not sure about the correct solution though, since I have no deeper knowledge of internals of Mono. Maybe it's enough to use Socket.OSSupportsIPv6 instead of Socket.SupportsIPv6 in System.Net.Dns.hostent_to_IPHostEntry?

Complete test code

using System;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.IO;

namespace IPV6Test
{
        class MainClass
        {
                public static void Main(string[] args)
                {
                        // Check IPv6 support
                        Console.WriteLine("Socket.OSSupportsIPv6: " + Socket.OSSupportsIPv6);
                        Console.WriteLine("Socket.SupportsIPv6: " + Socket.SupportsIPv6);

                        // Use reflection to change the IPv6 support
                        // remove coments to temporarily fix the issues
//                      var field = typeof(System.Net.Sockets.Socket).GetField("s_SupportsIPv6", BindingFlags.Static|BindingFlags.NonPublic);
//                      field.SetValue(null, true);
//                      Console.WriteLine("Socket.SupportsIPv6: " + Socket.SupportsIPv6);

                        // Test DNS lookup
                        var addresses = Dns.GetHostAddresses("ipv6.google.com");
                        foreach(var address in addresses)
                        {
                                Console.WriteLine(address.ToString());
                        }

                        // Test WebRequest to IPv6-only host
                        var webRequest = WebRequest.Create(@"http://ipv6.google.com");
                        using(var response = webRequest.GetResponse())
                        using(var content = response.GetResponseStream())
                        using(var reader = new StreamReader(content))
                        {
                                Console.Write(reader.ReadToEnd());
                        }
                }
        }
}
@greendeath

This comment has been minimized.

greendeath commented Feb 18, 2018

👍

@marek-safar marek-safar added this to the 2017-12 milestone Feb 19, 2018

@marek-safar

This comment has been minimized.

Member

marek-safar commented Feb 19, 2018

@baulig this looks quite serious/ugly I think we should try to get it into 2017-12

@marek-safar

This comment has been minimized.

Member

marek-safar commented Mar 1, 2018

@baulig any update on this?

@marek-safar marek-safar added this to Bugs Pool in Bugs Week via automation Mar 12, 2018

@alexischr alexischr moved this from Bugs Pool to In Progress in Bugs Week Mar 12, 2018

@alexischr alexischr self-assigned this Mar 12, 2018

alexischr added a commit to alexischr/mono that referenced this issue Mar 12, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes mono#6940

alexischr added a commit to alexischr/mono that referenced this issue Mar 12, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes mono#6940

alexischr added a commit to alexischr/mono that referenced this issue Mar 15, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes mono#6940

alexischr added a commit to alexischr/mono that referenced this issue Mar 15, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes mono#6940

alexischr added a commit to alexischr/mono that referenced this issue Mar 15, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes mono#6940

alexischr added a commit to alexischr/mono that referenced this issue Mar 15, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes mono#6940

alexischr added a commit to alexischr/mono that referenced this issue Mar 16, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes mono#6940

Bugs Week automation moved this from In Progress to Done Mar 16, 2018

alexischr added a commit that referenced this issue Mar 16, 2018

Merge pull request #7584 from alexischr/fix-gh-6940
[System.Net] Replace use of obsolete `SupportsIPv6` property.
@alexischr

This comment has been minimized.

Member

alexischr commented Mar 17, 2018

Thank you for figuring out the issue @TekkiWuff !

alexischr added a commit that referenced this issue Mar 19, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes #6940

alexischr added a commit that referenced this issue Mar 19, 2018

[System.Net] Replace use of obsolete `SupportsIPv6` property.
The obsolete property was always set to false. Fixes #6940

@luhenry luhenry moved this from Done to Archived in Bugs Week Mar 20, 2018

jonpryor added a commit to xamarin/xamarin-android that referenced this issue Mar 22, 2018

jonpryor added a commit to jonpryor/xamarin-android that referenced this issue Mar 24, 2018

jonpryor added a commit to xamarin/xamarin-android that referenced this issue Mar 24, 2018

jonpryor added a commit to xamarin/xamarin-android that referenced this issue Apr 25, 2018

Bump to mono/2018-02/0c5a524e (#1289)
Bumps to Java.Interop/master/0afb2b0f
Bumps to llvm/master/a9cfb50e.

Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=11771
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=15051
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=19436
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=45901
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=56071
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=58413
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=58413
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=58413
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=59184
fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60065
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60225
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60298
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60359
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60568
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60756
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60848
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60862
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60900
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60904
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=60986
Fixes: https://github.com/mono/mono/issues/59400
Fixes: mono/mono#6169
Fixes: mono/mono#6187
Fixes: mono/mono#6192
Fixes: mono/mono#6255
Fixes: mono/mono#6264
Fixes: mono/mono#6266
Fixes: mono/mono#6281
Fixes: mono/mono#6283
Fixes: mono/mono#6320
Fixes: mono/mono#6339
Fixes: mono/mono#6343
Fixes: mono/mono#6349
Fixes: mono/mono#6379
Fixes: mono/mono#6383
Fixes: mono/mono#6401.
Fixes: mono/mono#6411
Fixes: mono/mono#6414
Fixes: mono/mono#6490
Fixes: mono/mono#6721
Fixes: mono/mono#6767
Fixes: mono/mono#6777
Fixes: mono/mono#6848
Fixes: mono/mono#6940
Fixes: mono/mono#6948
Fixes: mono/mono#6998
Fixes: mono/mono#7016
Fixes: mono/mono#7085
Fixes: mono/mono#7086
Fixes: mono/mono#7095
Fixes: mono/mono#7137
Fixes: mono/mono#7184
Fixes: mono/mono#7240
Fixes: mono/mono#7262
Fixes: mono/mono#7289
Fixes: mono/mono#7338
Fixes: mono/mono#7356
Fixes: mono/mono#7364
Fixes: mono/mono#7378
Fixes: mono/mono#7389
Fixes: mono/mono#7460
Fixes: mono/mono#7535
Fixes: mono/mono#7536
Fixes: mono/mono#7610
Fixes: mono/mono#7624
Fixes: mono/mono#7637
Fixes: mono/mono#7655
Fixes: mono/mono#7657
Fixes: mono/mono#7685
Fixes: mono/mono#7786
Fixes: mono/mono#7792
Fixes: mono/mono#7822
Fixes: mono/mono#7860
Fixes: mono/mono#8089
Fixes: mono/mono#8267
Fixes: mono/mono#8409
Fixes: xamarin/maccore#628
Fixes: xamarin/maccore#629
Fixes: xamarin/maccore#673
Fixes: xamarin/maccore#673
Fixes: #1561

jonpryor added a commit to xamarin/xamarin-android that referenced this issue Aug 8, 2018

Bump to mono/mono:2018-04@f3a2216b (#1503)
Fixes: #1130
Fixes: #1561 (comment)
Fixes: #1845
Fixes: #1951

Context: https://bugzilla.xamarin.com/show_bug.cgi?id=10087
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=11771
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=12850
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=18941
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=19436
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=25444
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=33208
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=58413
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59184
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59400
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59779
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60065
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60843
Context: mono/mono#6174
Context: mono/mono#6178
Context: mono/mono#6180
Context: mono/mono#6181
Context: mono/mono#6186
Context: mono/mono#6187
Context: mono/mono#6211
Context: mono/mono#6266
Context: mono/mono#6579
Context: mono/mono#6666
Context: mono/mono#6752
Context: mono/mono#6801
Context: mono/mono#6812
Context: mono/mono#6848
Context: mono/mono#6940
Context: mono/mono#6948
Context: mono/mono#6998
Context: mono/mono#6999
Context: mono/mono#7016
Context: mono/mono#7085
Context: mono/mono#7086
Context: mono/mono#7095
Context: mono/mono#7134
Context: mono/mono#7137
Context: mono/mono#7145
Context: mono/mono#7184
Context: mono/mono#7240
Context: mono/mono#7262
Context: mono/mono#7289
Context: mono/mono#7338
Context: mono/mono#7356
Context: mono/mono#7364
Context: mono/mono#7378
Context: mono/mono#7389
Context: mono/mono#7449
Context: mono/mono#7460
Context: mono/mono#7535
Context: mono/mono#7536
Context: mono/mono#7537
Context: mono/mono#7565
Context: mono/mono#7588
Context: mono/mono#7596
Context: mono/mono#7610
Context: mono/mono#7613
Context: mono/mono#7620
Context: mono/mono#7624
Context: mono/mono#7637
Context: mono/mono#7655
Context: mono/mono#7657
Context: mono/mono#7661
Context: mono/mono#7685
Context: mono/mono#7696
Context: mono/mono#7729
Context: mono/mono#7786
Context: mono/mono#7792
Context: mono/mono#7805
Context: mono/mono#7822
Context: mono/mono#7828
Context: mono/mono#7860
Context: mono/mono#7864
Context: mono/mono#7903
Context: mono/mono#7920
Context: mono/mono#8089
Context: mono/mono#8143
Context: mono/mono#8267
Context: mono/mono#8311
Context: mono/mono#8340
Context: mono/mono#8409
Context: mono/mono#8417
Context: mono/mono#8430
Context: mono/mono#8698
Context: mono/mono#8701
Context: mono/mono#8712
Context: mono/mono#8721
Context: mono/mono#8726
Context: mono/mono#8866
Context: mono/mono#9023
Context: mono/mono#9031
Context: mono/mono#9033
Context: mono/mono#9044
Context: mono/mono#9179
Context: mono/mono#9318
Context: mono/mono#9318
Context: xamarin/maccore#628
Context: xamarin/maccore#629
Context: xamarin/maccore#673

jonpryor added a commit to xamarin/xamarin-android that referenced this issue Aug 13, 2018

Bump to mono/mono:2018-04@f3a2216b (#1503)
Fixes: #1130
Fixes: #1561 (comment)
Fixes: #1845
Fixes: #1951

Context: https://bugzilla.xamarin.com/show_bug.cgi?id=10087
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=11771
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=12850
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=18941
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=19436
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=25444
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=33208
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=58413
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59184
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59400
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=59779
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60065
Context: https://bugzilla.xamarin.com/show_bug.cgi?id=60843
Context: mono/mono#6174
Context: mono/mono#6178
Context: mono/mono#6180
Context: mono/mono#6181
Context: mono/mono#6186
Context: mono/mono#6187
Context: mono/mono#6211
Context: mono/mono#6266
Context: mono/mono#6579
Context: mono/mono#6666
Context: mono/mono#6752
Context: mono/mono#6801
Context: mono/mono#6812
Context: mono/mono#6848
Context: mono/mono#6940
Context: mono/mono#6948
Context: mono/mono#6998
Context: mono/mono#6999
Context: mono/mono#7016
Context: mono/mono#7085
Context: mono/mono#7086
Context: mono/mono#7095
Context: mono/mono#7134
Context: mono/mono#7137
Context: mono/mono#7145
Context: mono/mono#7184
Context: mono/mono#7240
Context: mono/mono#7262
Context: mono/mono#7289
Context: mono/mono#7338
Context: mono/mono#7356
Context: mono/mono#7364
Context: mono/mono#7378
Context: mono/mono#7389
Context: mono/mono#7449
Context: mono/mono#7460
Context: mono/mono#7535
Context: mono/mono#7536
Context: mono/mono#7537
Context: mono/mono#7565
Context: mono/mono#7588
Context: mono/mono#7596
Context: mono/mono#7610
Context: mono/mono#7613
Context: mono/mono#7620
Context: mono/mono#7624
Context: mono/mono#7637
Context: mono/mono#7655
Context: mono/mono#7657
Context: mono/mono#7661
Context: mono/mono#7685
Context: mono/mono#7696
Context: mono/mono#7729
Context: mono/mono#7786
Context: mono/mono#7792
Context: mono/mono#7805
Context: mono/mono#7822
Context: mono/mono#7828
Context: mono/mono#7860
Context: mono/mono#7864
Context: mono/mono#7903
Context: mono/mono#7920
Context: mono/mono#8089
Context: mono/mono#8143
Context: mono/mono#8267
Context: mono/mono#8311
Context: mono/mono#8340
Context: mono/mono#8409
Context: mono/mono#8417
Context: mono/mono#8430
Context: mono/mono#8698
Context: mono/mono#8701
Context: mono/mono#8712
Context: mono/mono#8721
Context: mono/mono#8726
Context: mono/mono#8866
Context: mono/mono#9023
Context: mono/mono#9031
Context: mono/mono#9033
Context: mono/mono#9044
Context: mono/mono#9179
Context: mono/mono#9318
Context: mono/mono#9318
Context: xamarin/maccore#628
Context: xamarin/maccore#629
Context: xamarin/maccore#673
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment