⚙️ The Request That Outlived the Client That Sent It
Every HttpContext carries a RequestAborted CancellationToken that fires the moment the client disconnects, closes the tab, or hits its own timeout – but it only does anything if the action actually passes it to the work being awaited. An action that ignores it keeps running a database query, an external API call, or a report generation job to completion for a response nobody is still there to receive.
🔎 The Problem
[HttpGet("report/{id}")]
public async Task<IActionResult> GetReport(int id)
{
// No CancellationToken parameter at all, so there's
// nothing here that could ever observe the client
// giving up. The query and the PDF render both run
// to completion even if the browser tab closed a
// full minute ago.
var data = await _db.Orders
.Where(o => o.ReportId == id)
.ToListAsync();
var pdf = await _reportBuilder.RenderAsync(data);
return File(pdf, "application/pdf");
}
✅ Fix: Thread RequestAborted Into Every Awaited Call
- Add a
CancellationTokenparameter to the action and let model binding fill it fromHttpContext.RequestAbortedautomatically – then pass that same token into everyToListAsync,HttpClientcall, and long-running helper the action awaits, so each one can stop the moment the client leaves. - Treat a resulting
OperationCanceledExceptionas the expected shutdown path, not an error – let ASP.NET Core’s built-in handling convert it into a quiet, logged cancellation instead of wrapping it in your own error-reporting pipeline where it’ll look like a real failure. - For work that genuinely shouldn’t stop just because the HTTP request did (a payment that already started, a write that must finish once begun), that’s a deliberate design choice – hand it off to a background job explicitly instead of letting it ride along on an HTTP request’s cancellation token by accident.
⚠️ Why This Is Easy to Miss
- A request that completes in under a second almost never gets cancelled mid-flight, so this only shows up as wasted database and CPU load on the slow, expensive endpoints – exactly the ones where the waste matters most.
- It’s invisible in local testing because you’re the only client and you rarely close the tab mid-request on purpose – it surfaces later as database load that doesn’t match the number of responses actually being sent.
A client that hung up isn’t waiting for an answer anymore – an action that doesn’t check for that keeps working for an audience that already left.

