title: Strange deadlock situation in ASP.NET Core Controller
body: <p>In my ASP.NET Core application I have a a seemingly very simple action. It awaits some value from an asynchronous method and then returns it as an OK-result:</p>
  
  <pre><code>public async Task&lt;IActionResult&gt; GetNextCommand()
  {
      var command = await LongPollManager.Instance.GetNextCommand(HttpContext.RequestAborted);
      return Ok(command);
  }
  </code></pre>
  
  <p>When I call this route with some HTTP client I can verify in the debugger that this asynchronous method returns the desired value and passes it to the Ok method:</p>
  
  <p><a href="https://i.stack.imgur.com/G81Pk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G81Pk.png" alt="enter image description here"></a></p>
  
  <p>If I let the debugger continue I would expect to get the result in my HTTP client. But the client never receives a response.</p>
  
  <p>When I then break the debugger I can see that the thread is blocked on some internal lock. You can see this in the current screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/mJTJe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mJTJe.png" alt="enter image description here"></a></p>
  
  <p>This behavior can be seen only since I made some changes in my <code>LongPollManager</code> class (which is actually quite complex and uses <code>TaskCompletionSource</code>s and <code>ConcurrentDictionarie</code>s, and <code>SemaphoreSlim</code>s internally).</p>
  
  <p>The thing that puzzles me is that it's actually not my own <code>GetNextCommand</code> method which is blocking, but the blocking seems to happen inside ASP.NET Core. Once execution is in line 29 and I got my <code>command</code> object, all the complicated asynchronous stuff of my <code>LongPollManager</code> class is over and I don't see how anything I change in <code>LongPollManager</code> can prevent ASP.NET Core from properly finishing the request.</p>
  
  <p>What could it be that ASP.NET Core is waiting here for? How can my code (which runs to line 29 without a deadlock) cause such a deadlock situation?</p>