Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1821

Persistent timeout

$
0
0

The following lines of code seem to constantly lead to a timeout exception and I'm not sure why? Note timeout set to 10s. The error is a "System.Threading.Tasks.TaskCanceledException' - 'The request was canceled due to the configured HttpClient.Timeout of 5 seconds elapsing"

Thanks

public static async Task<Dictionary<string, ProfileManifest>> GetProfiles()        {            Dictionary<string, ProfileManifest> result = [];            try            {                JsonNode node = await GetJsonFromUrl(Definition.RepoDistUrlProfileFile);                foreach (var entry in node.AsObject())                {                    var manifest = entry.Value.Deserialize<ProfileManifest>();                    if (manifest.VersionApp <= Definition.ProductVersion)                        result.Add(entry.Key, manifest);                }            }            catch (Exception ex)            {                Logger.LogException(ex);            }            return result;        }public static async Task<JsonNode> GetJsonFromUrl(string url)        {            HttpClient client = new()            {                Timeout = TimeSpan.FromMilliseconds(Config.HttpRequestTimeoutMs)            };            client.DefaultRequestHeaders.Accept.Clear();            client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");            Logger.Debug($"Downloading '{url}' ...");            string json = await client.GetStringAsync(url);            Logger.Debug($"json received: len {json?.Length}");            return JsonSerializer.Deserialize<JsonNode>(json);        }

Viewing all articles
Browse latest Browse all 1821

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>