I have a problem that occurs when i have deployed the code to the production server. It does not happen locally on my computer. When i run the line
var host = await Dns.GetHostEntryAsync(adresse);
The production environment freezes or awaits indefinitely. Why does this happen?
Here is the code:
public async Task<string> HentAsync(string ip)
{
if (string.IsNullOrWhiteSpace(ip) || kLoopbackIp.Contains(ip))
{
return string.Empty;
}
if (IpHostname.ContainsKey(ip))
{
UpdateAndRemoveOldElements(ip);
return IpHostname[ip].Item1;
}
try
{
IPAddress adresse = IPAddress.None;
if (!IPAddress.TryParse(ip, out adresse))
{
return string.Empty;
}
var host = await Dns.GetHostEntryAsync(adresse);
string hostname = host.HostName;
IpHostname.AddOrUpdate(ip,
new Tuple<string, DateTime>(hostname, DateTime.Now),
(x, y) => new Tuple<string, DateTime>(hostname, DateTime.Now));
return hostname;
}
catch (Exception)
{
// Tar i mot exception og returnerer tom string
return string.Empty;
}
}
UPDATE: The async method is called like this from a sync method that is doing the same thing (could this be the culprit).
public string Hent(string ip)
{
return HentAsync(ip).Result;
}