Skip to content

Commit 2018b8d

Browse files
authored
Session commit should time out if request is aborted (#552)
Currently, the session commit creates a time out solely on non-configurable value (which is currently set to 1 minute). This change links the request timeout so if a request is canceled, the commit will be canceled as well.
1 parent cda89e9 commit 2018b8d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Microsoft.AspNetCore.SystemWebAdapters.CoreServices/SessionMiddleware.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ private async Task ManageStateAsync(HttpContextCore context, ISessionStateFeatur
5656
{
5757
await _next(context);
5858

59-
using var cts = new CancellationTokenSource(CommitTimeout);
60-
6159
if (!details.IsReadOnly)
6260
{
63-
await state.CommitAsync(cts.Token);
61+
using var cts = new CancellationTokenSource(CommitTimeout);
62+
using var linked = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, context.RequestAborted);
63+
64+
await state.CommitAsync(linked.Token);
6465
}
6566
}
6667
finally

0 commit comments

Comments
 (0)