Skip to content
Discussion options

You must be logged in to vote

I would approach this by separating request cancellation, business transaction consistency, and idempotency state management. They have different lifecycle and reliability requirements.

  1. RequestAborted and cleanup

A client disconnect does not automatically terminate middleware execution. It signals cancellation, and downstream operations may throw OperationCanceledException.

An awaited finally block can still perform cleanup using a short-lived, independent cancellation token:

try
{
await next(context);
}
finally
{
using var cleanupCts =
new CancellationTokenSource(TimeSpan.FromSeconds(3));
try
{
await distributedLock.ReleaseAsync(
cleanupCts.Token);
}
catch (Exception ex)
{
logger.LogEr…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rodrigo-oliv-ciandt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants