title: HttpRequest not aborted (cancelled) on browser abort in ASP.NET Core MVC
body: <p>I wrote the following MVC Controller to test cancellation functionality:</p>
  
  <pre><code>class MyController : Controller
  {
      [HttpGet("api/CancelTest")]
      async Task&lt;IActionResult&gt; Get()
      {
          await Task.Delay(1000);
          CancellationToken token = HttpContext.RequestAborted;
          bool cancelled = token.IsCancellationRequested;
          logger.LogDebug(cancelled.ToString());
          return Ok();
      }
  }
  </code></pre>
  
  <p>Say, I want to cancel the request, so the value '<strong>true</strong>' is logged in the controller action above. This is possible server-side if the server implements the IHttpRequestLifetimeFeature. Luckily Kestrel does, and this can be accomplished the following way:</p>
  
  <pre><code>var feature = (IHttpRequestLifetimeFeature) HttpContext.Features[typeof(IHttpRequestLifetimeFeature)];
  feature.Abort();
  </code></pre>
  
  <p>The problem however is that I want to cancel the request on the client side. For example, in the browser. In pre-core versions of ASP.NET MVC/WebApi the cancellation token would automatically be cancelled if the browser aborted a request. Example: refresh the page a couple of times in Chrome. In the Network tab of the chrome dev tools you can now see the previous (unfinished) request be cancelled.</p>
  
  <p>The thing is: in ASP.NET Core running on Kestrel, I can only see the following entry in the log:</p>
  
  <blockquote>
    <p>Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException:
    Error -4081 ECANCELED operation canceled</p>
  </blockquote>
  
  <p>So the abort request from the browser DOES arrive and is handled by the Kestrel webserver. It does however not affect the RequestAborted property of the HttpContext in the controller, because the value '<strong>false</strong>' is still logged by the method.</p>
  
  <p><strong>Question:</strong>
  Is there a way to abort/cancel my controller's method, so that the HttpContext.RequestAborted property will be marked as cancelled? </p>
  
  <p>Perhaps I can make something that would subscribe to Kestrel's operation cancelled trigger and call the IHttpRequestLifetimeFeature.Abort() method?</p>
  
  <p><strong>Update:</strong>
  I did some further testing and it seems the HttpRequest <em>IS</em> in fact aborted, but there seems to be some kind of delay before the cancellation actually takes place. The delay is not time-factored, and seems to come straight from libuv (the library where the Kestrel webserver is build on top of). I posted more info on <a href="https://github.com/aspnet/KestrelHttpServer/issues/1103">https://github.com/aspnet/KestrelHttpServer/issues/1103</a></p>
  
  <p><strong>More updates:</strong>
  Issue has been moved to another one, because the previous one contained multiple problems. <a href="https://github.com/aspnet/KestrelHttpServer/issues/1139">https://github.com/aspnet/KestrelHttpServer/issues/1139</a></p>