Skip to content

Commit 78a6487

Browse files
authored
Use a timeout to commit session instead of HttpContext.RequestAborted (#234)
Redirect may cause the client to disconnect, but we still want to commit the session.
1 parent 53f12a4 commit 78a6487

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Threading;
56
using System.Threading.Tasks;
67
using System.Web.SessionState;
78
using Microsoft.AspNetCore.Http;
@@ -22,6 +23,8 @@ internal partial class SessionMiddleware
2223
[LoggerMessage(EventId = 1, Level = LogLevel.Warning, Message = "Creating session on demand by synchronously waiting on a potential asynchronous connection")]
2324
private partial void LogOnDemand();
2425

26+
private readonly TimeSpan CommitTimeout = TimeSpan.FromMinutes(1);
27+
2528
public SessionMiddleware(RequestDelegate next, ILogger<SessionMiddleware> logger)
2629
{
2730
_next = next;
@@ -56,7 +59,9 @@ private async Task ManageStateAsync(HttpContextCore context, SessionAttribute me
5659
try
5760
{
5861
await _next(context);
59-
await state.CommitAsync(context.RequestAborted);
62+
63+
using var cts = new CancellationTokenSource(CommitTimeout);
64+
await state.CommitAsync(cts.Token);
6065
}
6166
finally
6267
{

0 commit comments

Comments
 (0)