Bug 48995 - Dns resolution problems possibly related to F# / Windows Ubuntu subsystem
Summary: Dns resolution problems possibly related to F# / Windows Ubuntu subsystem
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http (show other bugs)
Version: 4.6.0 (C8)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-12-05 04:54 UTC by Darren
Modified: 2016-12-05 06:46 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Darren 2016-12-05 04:54:35 UTC
I am running mono 4.6.2 using the ubuntu subsystem in windows  (so linux under windows).   I traced a complex problem down to dns lookup failure.  A simple F# program shown below fails with this traceback.   The same same binary (compiled under ubuntu) runs fine in the enclosing windows host.  DNS works correctly outside mono.

let a = System.Net.Dns.GetHostEntry("www.nytimes.com")
printfn "res=%A" a
Unhandled Exception:
System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'www.nytimes.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00061] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at <StartupCode$t>.$T.main@ () [0x00000] in <5844e835ab706306a745038335e84458>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'www.nytimes.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00061] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at <StartupCode$t>.$T.main@ () [0x00000] in <5844e835ab706306a745038335e84458>:0

TO better understand the failure, I did a system trace of this simple program and it appears to contact the local DNS server, and even gets a reply, but interprets it as a failed DNS lookup.   Again, the same binary runs fine under windows.

Mono JIT compiler version 4.6.2 (Stable 4.6.2.7/08fd525 Mon Nov 14 12:30:00 UTC 2016)

Strace output with gratuitous timeofday lookups removed

mprotect(0x7f254bbe7000, 4096, PROT_READ) = 0
mprotect(0x7f254bdf4000, 4096, PROT_READ) = 0
munmap(0x7f2554767000, 35499)           = 0
stat("/etc/resolv.conf", {st_mode=S_IFREG|0644, st_size=141, ...}) = 0
open("/etc/resolv.conf", O_RDONLY|O_CLOEXEC) = 5
fstat(5, {st_mode=S_IFREG|0644, st_size=141, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2553420000
read(5, "#     DO NOT EDIT THIS FILE BY H"..., 512) = 141
read(5, "", 512)                        = 0
close(5)                                = 0
munmap(0x7f2553420000, 4096)            = 0
uname({sys="Linux", node="DPLATT-SURFACE", ...}) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 5
connect(5, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, 16) = 0
poll([{fd=5, events=POLLOUT}], 1, 0)    = 1 ([{fd=5, revents=POLLOUT}])
sendto(5, "\354\334\1\0\0\1\0\0\0\0\0\0\3www\7nytimes\3com\0\0\34\0"..., 33, MSG_NOSIGNAL, NULL, 0) = 33
poll([{fd=5, events=POLLIN}], 1, 5000)  = 1 ([{fd=5, revents=POLLIN}])
ioctl(5, FIONREAD, [127])               = 0
recvfrom(5, "\354\334\201\200\0\1\0\1\0\1\0\0\3www\7nytimes\3com\0\0\34\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, [16]) = 127
close(5)                                = 0
write(2, "\nUnhandled Exception:\nSystem.Net"..., 532
Unhandled Exception:
System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'www.nytimes.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00061] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at <StartupCode$t>.$T.main@ () [0x00000] in <5844e835ab706306a745038335e84458>:0
) = 532
write(2, "[ERROR] FATAL UNHANDLED EXCEPTIO"..., 545[ERROR] FATAL UNHANDLED EXCEPTION: System.Net.Sockets.SocketException (0x80004005): Could not resolve host 'www.nytimes.com'
  at System.Net.Dns.Error_11001 (System.String hostName) [0x00015] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostByName (System.String hostName) [0x00024] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00061] in <bd46d4d4f7964dfa9beea098499ab597>:0
  at <StartupCode$t>.$T.main@ () [0x00000] in <5844e835ab706306a745038335e84458>:0
) = 545
unlink("/dev/shm/mono.23519")           = 0
exit_group(1)                           = ?
+++ exited with 1 +++


Am I making some silly mistake or is there an issue with mono runtime for dns resolution?
For reference, the upstream DNS is supplied by a trendnet TEW-818DRU
Comment 1 Darren 2016-12-05 05:09:50 UTC
For what it's worth, I ran the same binary on another ubuntu system (different network, running linux nativel and earlier mono version  mono 4.2.3) and profiled the same calls.  Here are the parallel network sendto  calls and recvfrom calls.  The GOOD working one is first in both cases, and the BAD not working one is second.
I don't speak binary DNS lookups but they are sending slightly different requests and getting different responses. 

sendto  (4, "\332\343\1\0\0\1\0\0\0\0\0\0\3www\7nytimes\3com\0\0\1\0"..., 33, MSG_NOSIGNAL, NULL, 0) = 33
sendto  (5, "\354\334\1\0\0\1\0\0\0\0\0\0\3www\7nytimes\3com\0\0\34\0"..., 33, MSG_NOSIGNAL, NULL, 0) = 33



recvfrom(5, "\354\334\201\200\0\1\0\1\0\1\0\0\3www\7nytimes\3com\0\0\34\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, [16]) = 127
recvfrom(4, "\332\343\201\200\0\1\0\2\0\0\0\0\3www\7nytimes\3com\0\0\1\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("10.10.10.13")}, [16]) = 85
Comment 2 Darren 2016-12-05 05:26:15 UTC
And my admittedly newbie reading of that binary exchange with the two servers suggests that the not working mono 4.6.2 / dnslookup on my home network is trying IPv6.   Pretty sure that's not going to work.   The other earlier mono version that does succeed with same program is using IPv4 (on a corporate network where ironically ipv6 might actually work).  Still decoding the replies but I suspect that's the problem.  Not sure why mono is trying ipv6 out of the box and failing when it doesn't get a reply
Comment 3 Darren 2016-12-05 05:40:56 UTC
Checking these more carefully, I think I transposed the response lines, so here is the correct output.  As far as I can tell, both requests result in successful replies.
The 4th byte of the response has the response code, and it's identical in both cases.   I'm not sure why mono decides the latter reply is a DNS lookup failure.

GOODREQEST sendto  (4, "\332\343\1\0\0\1\0\0\0\0\0\0\3www\7nytimes\3com\0\0\1\0"..., 33, MSG_NOSIGNAL, NULL, 0) = 33
BADREQUEST sendto  (5, "\354\334\1\0\0\1\0\0\0\0\0\0\3www\7nytimes\3com\0\0\34\0"..., 33, MSG_NOSIGNAL, NULL, 0) = 33

GOODREPLY recvfrom(4, "\332\343\201\200\0\1\0\2\0\0\0\0\3www\7nytimes\3com\0\0\1\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("10.10.10.13")}, [16]) = 85
BADREPLY  recvfrom(5, "\354\334\201\200\0\1\0\1\0\1\0\0\3www\7nytimes\3com\0\0\34\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, [16]) = 127
Comment 4 Darren 2016-12-05 06:46:19 UTC
Sorry to bombard you with so much information, but more details from the trace of the bad dns lookup.  This time with the full message.  It looks to me very much as thought the DNS lookup succeeds.  the returned text contains the text of the correct resolution per nslookup,  so I think mono is misinterpreting the result as DNS lookup failure for some reason I'm probably not going to understand without wading through the code,

Darren


read(5, "", 512)                        = 0
close(5)                                = 0
munmap(0x7f97e6e40000, 4096)            = 0
uname({sys="Linux", node="DPLATT-SURFACE", ...}) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 5
connect(5, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, 16) = 0
poll([{fd=5, events=POLLOUT}], 1, 0)    = 1 ([{fd=5, revents=POLLOUT}])
sendto(5, "\220\202\1\0\0\1\0\0\0\0\0\0\3www\7nytimes\3com\0\0\34\0"..., 33, MSG_NOSIGNAL, NULL, 0) = 33
poll([{fd=5, events=POLLIN}], 1, 5000)  = 1 ([{fd=5, revents=POLLIN}])
ioctl(5, FIONREAD, [127])               = 0
recvfrom(5, "\220\202\201\200\0\1\0\1\0\1\0\0\3www\7nytimes\3com\0\0\34\0"..., 1024, 0, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("192.168.0.1")}, [16]) = 127
 | 00000  90 82 81 80 00 01 00 01  00 01 00 00 03 77 77 77  .............www |
 | 00010  07 6e 79 74 69 6d 65 73  03 63 6f 6d 00 00 1c 00  .nytimes.com.... |
 | 00020  01 c0 0c 00 05 00 01 00  00 00 01 00 18 07 6e 79  ..............ny |
 | 00030  74 69 6d 65 73 03 6d 61  70 06 66 61 73 74 6c 79  times.map.fastly |
 | 00040  03 6e 65 74 00 c0 39 00  06 00 01 00 00 00 09 00  .net..9......... |
 | 00050  2e 03 6e 73 31 c0 39 0a  68 6f 73 74 6d 61 73 74  ..ns1.9.hostmast |
 | 00060  65 72 06 66 61 73 74 6c  79 c0 18 78 2b 66 dd 00  er.fastly..x+f.. |
 | 00070  00 0e 10 00 00 02 58 00  09 3a 80 00 00 00 1e     ......X..:.....  |
close(5)                                = 0
write(2, "\nUnhandled Exception:\nSystem.Net"..., 532) = 532
write(2, "[ERROR] FATAL UNHANDLED EXCEPTIO"..., 545) = 545
unlink("/dev/shm/mono.23716")           = 0
exit_group(1)                           = ?
+++ exited with 1 +++

Note You need to log in before you can comment on or make changes to this bug.