Skip to content
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

Lang/Mono - Error on every app depending on Mono (DNS) #200

Closed
bserrao opened this issue Apr 8, 2018 · 12 comments
Closed

Lang/Mono - Error on every app depending on Mono (DNS) #200

bserrao opened this issue Apr 8, 2018 · 12 comments

Comments

@bserrao
Copy link

bserrao commented Apr 8, 2018

Every app i tried which depends on Mono (emby, sonarr, radarr, ...) i get the error bellow. Because of that apps are unable to do name resolution and consequent "internet" requests fail.
I've tried building Mono from Dport source and i've made it, but needed to deal with some errors. Anyways the result is the same.

`18-4-5 02:01:13.3|Debug|Api|[PUT] /api/config/host: 202.Accepted (88 ms)
18-4-5 02:01:13.3|Error|TaskExtensions|Task Error

[v2.0.0.5153] System.Net.WebException: DNS Name Resolution Failure: 'services.sonarr.tv'
at NzbDrone.Common.Http.Dispatchers.ManagedHttpDispatcher.GetResponse (NzbDrone.Common.Http.HttpRequest request, System.Net.CookieCon
tainer cookies) [0x0015e] in <7e93f23c2fc54b74802f7126f4e364f7>:0
at NzbDrone.Common.Http.Dispatchers.FallbackHttpDispatcher.GetResponse (NzbDrone.Common.Http.HttpRequest request, System.Net.CookieCo
ntainer cookies) [0x000b5] in <7e93f23c2fc54b74802f7126f4e364f7>:0
at NzbDrone.Common.Http.HttpClient.ExecuteRequest (NzbDrone.Common.Http.HttpRequest request) [0x0007e] in <7e93f23c2fc54b74802f7126f4
e364f7>:0
at NzbDrone.Common.Http.HttpClient.Execute (NzbDrone.Common.Http.HttpRequest request) [0x00000] in <7e93f23c2fc54b74802f7126f4e364f7>
:0
at NzbDrone.Common.Http.HttpClient.Get (NzbDrone.Common.Http.HttpRequest request) [0x00007] in <7e93f23c2fc54b74802f7126f4e364f7>:0
at NzbDrone.Common.Http.HttpClient.Get[T] (NzbDrone.Common.Http.HttpRequest request) [0x00000] in <7e93f23c2fc54b74802f7126f4e364f7>:
0`

I'm also trying to build the last stable version from Mono, but until now i was unable to do it.
On Freebsd the current version of Mono is working with the apps referred above.

@jrmarino
Copy link
Contributor

jrmarino commented Apr 8, 2018

patches accepted if you find one that solves the issue.
You might try opening the source and searching for those errors and seeing if there's some kind of CPP macro for freebsd that dragonfly also needs or something.

@bserrao
Copy link
Author

bserrao commented Apr 10, 2018

I managed to build mono 5.10.0.160, and after some fireworks :) i realized the final result is the same...
Since i'm out of solutions and don't have the knowledge or the time to keep debugging this issue (Also it appears i'm alone in this, so it doesn't feel right others spend time trying to solve it), i'm "forced" to move to another operating system. :( (Freebsd or Linux distro again)

Feel free to close this issue.
Thanks a lot for the support

@jrmarino
Copy link
Contributor

meaning you didn't attempt to "make patch" and search to code? solution might have been obvious if you're looking in the right file.
oh well.

@bserrao
Copy link
Author

bserrao commented Apr 10, 2018

oh well, i don't like to give up easily so... let's grep some code.

@bserrao
Copy link
Author

bserrao commented Apr 10, 2018

I made some progress... So it appears to me (i don't remember much of c#) that mono "thinks" there's no socket support for ipv4 and ipv6.
I've adapted and used some code i've found to test this DNS thing

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

namespace IPTest
{
        class MainClass
        {
                public static void Main(string[] args)
                {
                        // Check IPv4 support
                        Console.WriteLine("Socket.OSSupportsIPv4: " + Socket.OSSupportsIPv4);
                        Console.WriteLine("Socket.SupportsIPv4: " + Socket.SupportsIPv4);

                        Console.WriteLine("Socket.OSSupportsIPv6: " + Socket.OSSupportsIPv6);
                        Console.WriteLine("Socket.SupportsIPv6: " + Socket.SupportsIPv6);

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

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

                        // Test DNS lookup
                        var addresses = Dns.GetHostAddresses("www.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());
                        }
                }
        }
}

Now, running this system reports:

Socket.OSSupportsIPv4: False
Socket.SupportsIPv4: False
Socket.OSSupportsIPv6: False
Socket.SupportsIPv6: False

And the DNS Lookup fails:

Unhandled Exception:
System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'www.google.com'

If i uncoment the part of the code i set those variables to True, compile and run, magic happens :)

Socket.SupportsIPv4: True
Socket.OSSupportsIPv4: True
Socket.OSSupportsIPv6: False
172.217.16.228

Now, i've no ideia how mono sets this variables to start... i've already looked at make configure output but haven't found anything. I'm going to open an issue on Mono github in the hope they can point me in the right direction.
I'm not sure if this is exactly the same error i'm getting in the apps, but the result is similar so i guess it might be related. (Looking @ the code based on the error took me here somehow, the rest is just pure c# without any reference to the used platform)

@jrmarino
Copy link
Contributor

Do your machine support IPv6?
I'm scanning mono code and it's setting the AF family to 23 for IPv6, but on *BSD the value should be 28. However, IPv4 is set to 2 which is correct for FreeBSD and DragonFly. So it seems like IPv4 should be detected and IPv6 should be shown as unsupported.

@bserrao
Copy link
Author

bserrao commented Apr 12, 2018

Yes, i think it supports IPv6.
I've rebuild mono after setting AF family to 28 without sucess.

According to Mono devs:

The code goes through

mono/mcs/class/System/System.Net.Sockets/Socket.cs

Line 2803 in 18d3890

static bool IsProtocolSupported (NetworkInterfaceComponent networkInterface)
which in your case should hit
mono/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs

Line 280 in 18d3890

public override NetworkInterface [] GetAllNetworkInterfaces ()
but you'll need to debug it there to see what is wrong

So, i need to figure out why mono is initialized with both Socket.SupportsIPvx and Socket.OSSupportsIPvx to false.

@jrmarino
Copy link
Contributor

  1. I doubt that's the only place to change and
  2. it's not a mystery. The socket fails to initialize so it's set to "not supported". I've found the code. That's how I traced the AF family back to the wrong 23.

There's no way IPv6 should work when using value of 23.

@jrmarino
Copy link
Contributor

the question is whether it's IPv4 is failing everywhere or just your machine. As far as I can tell, it should work.

@bserrao
Copy link
Author

bserrao commented Apr 12, 2018

That's a good question :) One i also would like to know the answer.
Also i don't know how can i debug any further the reason why the socket fails to initialize.

@tuxillo
Copy link
Member

tuxillo commented Jun 26, 2022

I just checked and it seems it's still the case:

$ mono iptest.exe
$ mono --version
Mono JIT compiler version 5.10.1.57 (5.10.1.57 Sun Jun  5 20:11:06 UTC 2022)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        Interpreter:   yes
        LLVM:          supported, not enabled.
        GC:            sgen (concurrent by default)

$ mono iptest.exe
Socket.OSSupportsIPv4: False
Socket.SupportsIPv4: False
Socket.OSSupportsIPv6: False
Socket.SupportsIPv6: False

Unhandled Exception:
System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'www.google.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <4ad65efbce7f4e97a7595d004f41cd38>: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 <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00027] in <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00052] in <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00056] in <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at IPTest.MainClass.Main (System.String[] args) [0x00075] in <b70060805dad406fb1c110b42270f91e>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'www.google.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <4ad65efbce7f4e97a7595d004f41cd38>: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 <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00027] in <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00052] in <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at System.Net.Dns.GetHostAddresses (System.String hostNameOrAddress) [0x00056] in <4ad65efbce7f4e97a7595d004f41cd38>:0 
  at IPTest.MainClass.Main (System.String[] args) [0x00075] in <b70060805dad406fb1c110b42270f91e>:0 

tuxillo added a commit to DragonFlyBSD/DeltaPorts that referenced this issue Jun 26, 2022
  - Since we're already using 'USES= alias', an additional
    patch to identify us as FreeBSD internally in mono helped
    solving DragonFlyBSD/DPorts#200
tuxillo added a commit to DragonFlyBSD/DeltaPorts that referenced this issue Jun 26, 2022
  - Since we're already using 'USES= alias', an additional
    patch to identify us as FreeBSD internally in mono helped
    solving DragonFlyBSD/DPorts#200
@tuxillo
Copy link
Member

tuxillo commented Jun 26, 2022

With commit, at least IPv4 is fixed: DragonFlyBSD/DeltaPorts@531ba20

leaf:/home/tuxillo/temp> mono iptest.exe
Socket.OSSupportsIPv4: True
Socket.SupportsIPv4: True
Socket.OSSupportsIPv6: False
Socket.SupportsIPv6: False
142.250.191.68

Unhandled Exception:
System.Net.WebException: Error: NameResolutionFailure
  at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00058] in <b82b90902e6346a2a693ea4ea740c793>:0 
  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in <b82b90902e6346a2a693ea4ea740c793>:0 
  at IPTest.MainClass.Main (System.String[] args) [0x000b5] in <716c37e27f3d4d66b28504b24abe9986>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.WebException: Error: NameResolutionFailure
  at System.Net.HttpWebRequest.EndGetResponse (System.IAsyncResult asyncResult) [0x00058] in <b82b90902e6346a2a693ea4ea740c793>:0 
  at System.Net.HttpWebRequest.GetResponse () [0x0000e] in <b82b90902e6346a2a693ea4ea740c793>:0 
  at IPTest.MainClass.Main (System.String[] args) [0x000b5] in <716c37e27f3d4d66b28504b24abe9986>:0 

That's good enough for us for now, we don't have a lot of time. If anybody can investigate the IPv6, please open a new issue. Thanks!

@tuxillo tuxillo closed this as completed Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants