Main Site Documentation

Fez Cobra: Dns.GetHostEntry timeout with disconnected network


#1

I’m currently experiencing a problem on a Fez Cobra, in the call to Dns.GetHostEntry(), when there is no active network connection (cable disconnected), or if there is no actual DNS server on the IP which has been configured using MFDeploy. The board is running on version 4.1.2821.0.

The problem is the timeout for this call seems to be about 60/70 seconds, and sometimes it doesn’t seem to time out (and the code blocks my program). As a result is my Fez becomes almost unresponsive using MFDeploy (no ping reply, errors when opening network configuration). Using a separate thread to do the DNS lookup doesn’t work either.

Relevant code:
ServerUtility.DoDebug(“DNS Test”);
IPHostEntry entry = Dns.GetHostEntry(“www.xs4all.nl”);
ServerUtility.DoDebug("DNS: " + entry.AddressList[0]);

The DoDebug function prints to console, with timestamps. The network settings are correct; with cable connected it works, cable disconnected doesn’t.

Call with network cable connected:
00:02:13.534 : Static IP
00:02:13.544 : DNS Test
00:02:19.573 : DNS: 194.109.6.92

Call with cable disconnected:
00:03:34.617 : Start load of assembly
00:03:34.692 : Static IP
00:03:34.702 : DNS Test
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (1) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### TriniT.MicroFramework.TcpInputOutputServer.TcpInputOutputServer::ShortDNSTest [IP: 0015] ####
#### TriniT.MicroFramework.TcpInputOutputServer.TcpInputOutputServer::Main [IP: 0066] ####
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
A first chance exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = -1
#### SocketException ErrorCode = -1
00:04:43.967 : Failed to start server: Exception was thrown: System.Net.Sockets.SocketException
00:04:43.977 : DNS Test
(after this, test restarts)

Is it possible to lower the timeout?

As a workaround I’ve built in pings to gateway and DNS, and a connect to port 53 of the DNS server, but I would still like to know if there is a solution to this problem.


#2

Well, I have background in Windows development and hoped this could be solved with a simple solution like a setting to lower the timeout. I guess we’ll have to use the extended checks in future projects as well.