HttpClient.GetAsync immediately throws TaskCanceledException
<p>I had a working code that was returning something from my CommonRestClient(which is simple wrapper for HttpClient):</p>

<pre><code>public async Task&lt;IActionResult&gt; Index()
{
    var uri = _baseUri.Concat(AvalancheServiceAdresses.NodeService);
    using (var client = new CommonRestClient(uri))
    {
        var result = await client.GetAsync&lt;List&lt;NodeInfoContract&gt;&gt;(new Uri(NodeServiceConstant.NodesContractUrl, UriKind.Relative), null);
        return View(result);
    }
}
</code></pre>

<p>It worked fine and i was happy. Until I decide to move my code from view in another class, which should incapsulate entire REST logic and provide an OOP API. </p>

<p>So now my index looks like:</p>

<pre><code>public async Task&lt;IActionResult&gt; Index()
{
    var nodeInfoContracts = await _configManager.GetNodesList();
    return View(nodeInfoContracts);
}
</code></pre>

<p>where <code>GetNodesList</code> is</p>

<pre><code>public ConfiguredTaskAwaitable&lt;List&lt;NodeInfoContract&gt;&gt; GetNodesList()
{
    var uri = _baseUri.Concat(AvalancheServiceAdresses.NodeService);
    using (var client = new CommonRestClient(uri))
    {
        return client.GetAsync&lt;List&lt;NodeInfoContract&gt;&gt;(new Uri(NodeServiceConstant.NodesContractUrl, UriKind.Relative), null);
    }
}
</code></pre>

<p>It's clear that provided codes are equal. </p>

<p>But now it always throws an exception when I try to get a result. In my <code>GetAsync</code> method it fails on following line with <code>TaskCanceledException</code>:</p>

<pre><code>var response = await _client.GetAsync(url).ConfigureAwait(false);
</code></pre>

<p>But it's interestring: when I place a breakpoint on this line and step over its works fine. So here we have race condition or similar.</p>

<p>Why am I getting it? I tried to place CondigureAwait false/true, combining some code, but it always throws an error when breakpoints are off. I checked timeout which is several minutes, it can't cause this error. </p>