For starters, this is a discussion if anyone of you guys does such a thing as request cancellation in WebAPI controllers (probably also applicable for MVC).
What I mean in particular is a scenario like the following: A client (browser typically) starts a request, navigates away or more general, aborts the request for any reason. Now, the request is aborted on the client side and will no longer be considered. But on the server side the request is still executing and typically might be doing two things especially interesting:
- Make a (heavy) DB-Query
- Make a (heavy) service call to another service
And all for nothing in the end (at least when it's a side-effect free read operation at least).
Does somebody handle cancellation of the ongoing query/service call in such a case?
What I know is that a CancellationToken
can be passed in the API-Controller (even though I couldn't get it working so that cancellation was really requested when aborting from the client).
This CancellationToken
, in theory, would need to be passed down to all lower layers to handle a probable cancellation of database and service calls.