From 2c19d084481e6a710d47ce72c357b1c1a6340531 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Mon, 29 May 2017 02:07:53 +0100
Subject: cleanup util.cs get dns
---
OpenSim/Framework/Util.cs | 157 +++++++++++++++++++++++-----------------------
1 file changed, 80 insertions(+), 77 deletions(-)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 83d9df1..e3d89dc 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -429,64 +429,6 @@ namespace OpenSim.Framework
return regionCoord << 8;
}
- public static IPEndPoint getEndPoint(IPAddress ia, int port)
- {
- if(ia == null)
- return null;
-
- IPEndPoint newEP = null;
- try
- {
- newEP = new IPEndPoint(ia, port);
- }
- catch
- {
- newEP = null;
- }
- return newEP;
- }
-
- public static IPEndPoint getEndPoint(string hostname, int port)
- {
- IPAddress ia = null;
- // If it is already an IP, don't resolve it - just return directly
- // we should not need this
- if (IPAddress.TryParse(hostname, out ia))
- {
- if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
- return null;
- return getEndPoint(ia, port);
- }
-
- // Reset for next check
- ia = null;
- try
- {
- foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
- {
- if (ia == null)
- ia = Adr;
-
- if (Adr.AddressFamily == AddressFamily.InterNetwork)
- {
- ia = Adr;
- break;
- }
- }
- }
- catch // (SocketException e)
- {
- /*throw new Exception(
- "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
- e + "' attached to this exception", e);*/
- // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
- // Reason is, on systems such as OSgrid it has occured that known hostnames stop
- // resolving and thus make surrounding regions crash out with this exception.
- return null;
- }
-
- return getEndPoint(ia,port);
- }
public static bool checkServiceURI(string uristr, out string serviceURI)
{
@@ -1066,38 +1008,99 @@ namespace OpenSim.Framework
/// An IP address, or null
public static IPAddress GetHostFromDNS(string dnsAddress)
{
- // Is it already a valid IP? No need to look it up.
- IPAddress ipa;
- if (IPAddress.TryParse(dnsAddress, out ipa))
- return ipa;
+ // If it is already an IP, avoid possible broken mono from seeing it
+ IPAddress ia = null;
+ if (IPAddress.TryParse(dnsAddress, out ia) && ia != null)
+ {
+ if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
+ return null;
+ return ia;
+ }
+ // Reset for next check
+ ia = null;
+ try
+ {
+ foreach (IPAddress Adr in Dns.GetHostAddresses(dnsAddress))
+ {
+ if (ia == null)
+ ia = Adr;
- IPAddress[] hosts = null;
+ if (Adr.AddressFamily == AddressFamily.InterNetwork)
+ {
+ ia = Adr;
+ break;
+ }
+ }
+ }
+ catch // (SocketException e)
+ {
+ /*throw new Exception(
+ "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
+ e + "' attached to this exception", e);*/
+ // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
+ // Reason is, on systems such as OSgrid it has occured that known hostnames stop
+ // resolving and thus make surrounding regions crash out with this exception.
+ return null;
+ }
+ return ia;
+ }
+
+ public static IPEndPoint getEndPoint(IPAddress ia, int port)
+ {
+ if(ia == null)
+ return null;
- // Not an IP, lookup required
+ IPEndPoint newEP = null;
try
{
- hosts = Dns.GetHostEntry(dnsAddress).AddressList;
+ newEP = new IPEndPoint(ia, port);
}
- catch (Exception e)
+ catch
{
- m_log.WarnFormat("[UTIL]: An error occurred while resolving host name {0}, {1}", dnsAddress, e);
-
- // Still going to throw the exception on for now, since this was what was happening in the first place
- throw e;
+ newEP = null;
}
+ return newEP;
+ }
- foreach (IPAddress host in hosts)
+ public static IPEndPoint getEndPoint(string hostname, int port)
+ {
+ IPAddress ia = null;
+ // If it is already an IP, avoid possible broken mono from seeing it
+ if (IPAddress.TryParse(hostname, out ia) && ia != null)
{
- if (host.AddressFamily == AddressFamily.InterNetwork)
+ if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
+ return null;
+ return getEndPoint(ia, port);
+ }
+
+ // Reset for next check
+ ia = null;
+ try
+ {
+ foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
{
- return host;
+ if (ia == null)
+ ia = Adr;
+
+ if (Adr.AddressFamily == AddressFamily.InterNetwork)
+ {
+ ia = Adr;
+ break;
+ }
}
}
+ catch // (SocketException e)
+ {
+ /*throw new Exception(
+ "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
+ e + "' attached to this exception", e);*/
+ // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
+ // Reason is, on systems such as OSgrid it has occured that known hostnames stop
+ // resolving and thus make surrounding regions crash out with this exception.
+ return null;
+ }
- if (hosts.Length > 0)
- return hosts[0];
-
- return null;
+ return getEndPoint(ia,port);
}
public static Uri GetURI(string protocol, string hostname, int port, string path)
--
cgit v1.1
From 27afe136d4ef1cf700802cc4d719156f0445f2b4 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Mon, 29 May 2017 03:13:56 +0100
Subject: mono is a total crap
---
OpenSim/Framework/Util.cs | 41 ++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e3d89dc..3ddeafb 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1064,6 +1064,9 @@ namespace OpenSim.Framework
public static IPEndPoint getEndPoint(string hostname, int port)
{
+ if(String.IsNullOrWhiteSpace(hostname))
+ return null;
+
IPAddress ia = null;
// If it is already an IP, avoid possible broken mono from seeing it
if (IPAddress.TryParse(hostname, out ia) && ia != null)
@@ -1075,31 +1078,31 @@ namespace OpenSim.Framework
// Reset for next check
ia = null;
- try
+#if (_MONO)
+ // mono is a TOTAL CRAP
+ int retry = 3;
+ while(ia == null && retry-- >= 0)
+#endif
{
- foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
+ try
{
- if (ia == null)
- ia = Adr;
-
- if (Adr.AddressFamily == AddressFamily.InterNetwork)
+ foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
{
- ia = Adr;
- break;
+ if (ia == null)
+ ia = Adr;
+
+ if (Adr.AddressFamily == AddressFamily.InterNetwork)
+ {
+ ia = Adr;
+ break;
+ }
}
}
+ catch // (SocketException e)
+ {
+ ia = null;
+ }
}
- catch // (SocketException e)
- {
- /*throw new Exception(
- "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
- e + "' attached to this exception", e);*/
- // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
- // Reason is, on systems such as OSgrid it has occured that known hostnames stop
- // resolving and thus make surrounding regions crash out with this exception.
- return null;
- }
-
return getEndPoint(ia,port);
}
--
cgit v1.1
From 7be6e16555a25177128f6767661387cdffe084cc Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Mon, 29 May 2017 03:41:09 +0100
Subject: no.. still a fail
---
OpenSim/Framework/Util.cs | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 3ddeafb..fe84498 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1078,31 +1078,25 @@ namespace OpenSim.Framework
// Reset for next check
ia = null;
-#if (_MONO)
- // mono is a TOTAL CRAP
- int retry = 3;
- while(ia == null && retry-- >= 0)
-#endif
+ try
{
- try
+ foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
{
- foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
- {
- if (ia == null)
- ia = Adr;
+ if (ia == null)
+ ia = Adr;
- if (Adr.AddressFamily == AddressFamily.InterNetwork)
- {
- ia = Adr;
- break;
- }
+ if (Adr.AddressFamily == AddressFamily.InterNetwork)
+ {
+ ia = Adr;
+ break;
}
}
- catch // (SocketException e)
- {
- ia = null;
- }
}
+ catch // (SocketException e)
+ {
+ ia = null;
+ }
+
return getEndPoint(ia,port);
}
--
cgit v1.1
From 8f86de265c6187a61dde12fb122c1ae017b6ecf6 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Mon, 29 May 2017 05:22:21 +0100
Subject: some cleanup and assume Linux/mono DNS is just broken...
---
OpenSim/Framework/Util.cs | 76 ++++++++++++++++++++++++++---------------------
1 file changed, 42 insertions(+), 34 deletions(-)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index fe84498..061743d 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1009,6 +1009,9 @@ namespace OpenSim.Framework
public static IPAddress GetHostFromDNS(string dnsAddress)
{
// If it is already an IP, avoid possible broken mono from seeing it
+ if(String.IsNullOrWhiteSpace(dnsAddress))
+ return null;
+
IPAddress ia = null;
if (IPAddress.TryParse(dnsAddress, out ia) && ia != null)
{
@@ -1016,31 +1019,31 @@ namespace OpenSim.Framework
return null;
return ia;
}
- // Reset for next check
- ia = null;
+
+ IPHostEntry IPH;
try
{
- foreach (IPAddress Adr in Dns.GetHostAddresses(dnsAddress))
- {
- if (ia == null)
- ia = Adr;
-
- if (Adr.AddressFamily == AddressFamily.InterNetwork)
- {
- ia = Adr;
- break;
- }
- }
+ IPH = Dns.GetHostEntry(dnsAddress);
}
catch // (SocketException e)
{
- /*throw new Exception(
- "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
- e + "' attached to this exception", e);*/
- // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
- // Reason is, on systems such as OSgrid it has occured that known hostnames stop
- // resolving and thus make surrounding regions crash out with this exception.
+ return null;
+ }
+
+ if(IPH == null || IPH.AddressList.Length == 0)
return null;
+
+ ia = null;
+ foreach (IPAddress Adr in IPH.AddressList)
+ {
+ if (ia == null)
+ ia = Adr;
+
+ if (Adr.AddressFamily == AddressFamily.InterNetwork)
+ {
+ ia = Adr;
+ break;
+ }
}
return ia;
}
@@ -1075,26 +1078,31 @@ namespace OpenSim.Framework
return null;
return getEndPoint(ia, port);
}
-
- // Reset for next check
- ia = null;
+
+ IPHostEntry IPH;
try
{
- foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
- {
- if (ia == null)
- ia = Adr;
-
- if (Adr.AddressFamily == AddressFamily.InterNetwork)
- {
- ia = Adr;
- break;
- }
- }
+ IPH = Dns.GetHostEntry(hostname);
}
catch // (SocketException e)
{
- ia = null;
+ return null;
+ }
+
+ if(IPH == null || IPH.AddressList.Length == 0)
+ return null;
+
+ ia = null;
+ foreach (IPAddress Adr in IPH.AddressList)
+ {
+ if (ia == null)
+ ia = Adr;
+
+ if (Adr.AddressFamily == AddressFamily.InterNetwork)
+ {
+ ia = Adr;
+ break;
+ }
}
return getEndPoint(ia,port);
--
cgit v1.1
From a317bba8cf4783b9f664c4b4bc9974eedbca6feb Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Mon, 29 May 2017 07:11:13 +0100
Subject: cache endpoints (and other paths) dns requests for 5min, this delay
should be acceptable in all cases ?
---
OpenSim/Framework/Util.cs | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 061743d..a3c7750 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -991,6 +991,8 @@ namespace OpenSim.Framework
return output.ToString();
}
+ static ExpiringCache dnscache = new ExpiringCache();
+
///
/// Converts a URL to a IPAddress
///
@@ -1008,15 +1010,20 @@ namespace OpenSim.Framework
/// An IP address, or null
public static IPAddress GetHostFromDNS(string dnsAddress)
{
- // If it is already an IP, avoid possible broken mono from seeing it
if(String.IsNullOrWhiteSpace(dnsAddress))
return null;
IPAddress ia = null;
+ if(dnscache.TryGetValue(dnsAddress, out ia) && ia != null)
+ return ia;
+
+ ia = null;
+ // If it is already an IP, don't let GetHostEntry see it
if (IPAddress.TryParse(dnsAddress, out ia) && ia != null)
{
if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
return null;
+ dnscache.AddOrUpdate(dnsAddress, ia, 300);
return ia;
}
@@ -1027,7 +1034,7 @@ namespace OpenSim.Framework
}
catch // (SocketException e)
{
- return null;
+ return null;
}
if(IPH == null || IPH.AddressList.Length == 0)
@@ -1045,6 +1052,8 @@ namespace OpenSim.Framework
break;
}
}
+ if(ia != null)
+ dnscache.AddOrUpdate(dnsAddress, ia, 300);
return ia;
}
@@ -1071,14 +1080,22 @@ namespace OpenSim.Framework
return null;
IPAddress ia = null;
- // If it is already an IP, avoid possible broken mono from seeing it
+ if(dnscache.TryGetValue(hostname, out ia) && ia != null)
+ return getEndPoint(ia, port);
+
+ ia = null;
+
+ // If it is already an IP, don't let GetHostEntry see it
if (IPAddress.TryParse(hostname, out ia) && ia != null)
{
if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
return null;
+
+ dnscache.AddOrUpdate(hostname, ia, 300);
return getEndPoint(ia, port);
}
-
+
+
IPHostEntry IPH;
try
{
@@ -1086,7 +1103,7 @@ namespace OpenSim.Framework
}
catch // (SocketException e)
{
- return null;
+ return null;
}
if(IPH == null || IPH.AddressList.Length == 0)
@@ -1105,6 +1122,9 @@ namespace OpenSim.Framework
}
}
+ if(ia != null)
+ dnscache.AddOrUpdate(hostname, ia, 300);
+
return getEndPoint(ia,port);
}
--
cgit v1.1
From 91caf98308e4a5f371f9a25adfb4084ff5bfbc34 Mon Sep 17 00:00:00 2001
From: UbitUmarov
Date: Mon, 29 May 2017 07:48:09 +0100
Subject: change servicePoint dns expire also to 5min, let the endpoints expire
slide. This should reduce impact of absurd dns fails observed on my test
ubuntu VM
---
OpenSim/Framework/Util.cs | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Util.cs')
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index a3c7750..f52a84c 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -991,7 +991,7 @@ namespace OpenSim.Framework
return output.ToString();
}
- static ExpiringCache dnscache = new ExpiringCache();
+ private static ExpiringCache dnscache = new ExpiringCache();
///
/// Converts a URL to a IPAddress
@@ -1015,7 +1015,10 @@ namespace OpenSim.Framework
IPAddress ia = null;
if(dnscache.TryGetValue(dnsAddress, out ia) && ia != null)
+ {
+ dnscache.AddOrUpdate(dnsAddress, ia, 300);
return ia;
+ }
ia = null;
// If it is already an IP, don't let GetHostEntry see it
@@ -1081,7 +1084,10 @@ namespace OpenSim.Framework
IPAddress ia = null;
if(dnscache.TryGetValue(hostname, out ia) && ia != null)
+ {
+ dnscache.AddOrUpdate(hostname, ia, 300);
return getEndPoint(ia, port);
+ }
ia = null;
--
cgit v1.1