We have code in the field that tries to access www.microsoft.com through code. In the past 6 weeks or so it has been timing out after 100 seconds. If I try it again without closing the app, it works. Do you know if something changed on the side? It was working fine before. This GetAsync() call fails on the first try:
With this main method in a console app, the error can be reproduced. Passing in a parameter of 2 from the command line, the first attempt will fail, the second will succeed.
internal class Program
{
static void Main(string[] args)
{
var count = args?.Length > 0 ? int.Parse(args[0]) : 1;
for (int i = 0; i < count; i++)
{
var sw = new Stopwatch();
Console.WriteLine($"Request attempt number {i}");
sw.Start();
try
{
using var client = new HttpClient();
using var response = client.GetAsync("http://www.microsoft.com", new CancellationToken()).Result;
Console.WriteLine($"Date: {response.Headers.Date.GetValueOrDefault()}");
Console.WriteLine($"Status code: {response.StatusCode}");
Dictionary<string, string> ss
= response.Headers.ToDictionary(a => a.Key, a => string.Join(";", a.Value));
foreach (var entry in ss)
{
Console.WriteLine($"{entry.Key}: {entry.Value}");
}
}
catch (AggregateException ae)
{
foreach (var innerException in ae.Flatten().InnerExceptions)
{
Console.WriteLine(
$"Exception type: {innerException.GetType()}, message - {innerException.Message}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception type: {ex.GetType()}, message - {ex.Message}");
}
sw.Stop();
Console.WriteLine($"Total elapsed time: {sw.ElapsedMilliseconds / 1000} seconds");
}
}
}