Comments (6)
There shouldn't be any relation between session and keep-alives. Can you share the application logs for before and after?
from session.
To produce these logs I launched ASP.NET core behind my nginx reverse proxy, opened a new incognito browser window and requested the same URL three times via a URL pointing to nginx. I used a single session variable which was a counter being incremented. In the failure case the counter does not persist and remains at 1.
Working case (Connection = keep-alive):
Running aspnet
[?1h=Hosting environment: Production
Content root path: /dotnetapp
Now listening on: http://[::]:5000
Application started. Press Ctrl+C to shut down.
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://remove/
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method Woo.Web.Controllers.HomepageController.Index (Woo.Web) with arguments ((n
ull)) - ModelState is Valid
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action Woo.Web.Controllers.HomepageController.Index (Woo.Web) in 840.0717ms
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 1111.6613ms 200 text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://remove/
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method Woo.Web.Controllers.HomepageController.Index (Woo.Web) with arguments ((n
ull)) - ModelState is Valid
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action Woo.Web.Controllers.HomepageController.Index (Woo.Web) in 4.0174ms
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 7.6ms 200 text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://remove/
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method Woo.Web.Controllers.HomepageController.Index (Woo.Web) with arguments ((n
ull)) - ModelState is Valid
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action Woo.Web.Controllers.HomepageController.Index (Woo.Web) in 2.7991ms
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 5.4859ms 200 text/plain; charset=utf-8
Failure case (Connection = close):
Running aspnet
[?1h=Hosting environment: Production
Content root path: /dotnetapp
Now listening on: http://[::]:5000
Application started. Press Ctrl+C to shut down.
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://remove/
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method Woo.Web.Controllers.HomepageController.Index (Woo.Web) with arguments ((n
ull)) - ModelState is Valid
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action Woo.Web.Controllers.HomepageController.Index (Woo.Web) in 881.3667ms
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Session.SessionMiddleware[10]
Committing the session was canceled.
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 1162.6012ms 200 text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://remove/
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method Woo.Web.Controllers.HomepageController.Index (Woo.Web) with arguments ((n
ull)) - ModelState is Valid
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action Woo.Web.Controllers.HomepageController.Index (Woo.Web) in 3.7355ms
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Session.SessionMiddleware[10]
Committing the session was canceled.
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 6.014ms 200 text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://remove/
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
Executing action method Woo.Web.Controllers.HomepageController.Index (Woo.Web) with arguments ((n
ull)) - ModelState is Valid
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ContentResultExecutor[1]
Executing ContentResult with HTTP Response ContentType of text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Executed action Woo.Web.Controllers.HomepageController.Index (Woo.Web) in 11.195ms
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Session.SessionMiddleware[10]
Committing the session was canceled.
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 12.8115ms 200 text/plain; charset=utf-8
[40m[32minfo[39m[22m[49m: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
My test controller:
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Distributed;
using System;
using System.Collections.Generic;
using System.Text;
namespace Woo.Web.Controllers
{
[Route("")]
public class HomepageController : Controller
{
private const string CountKey = "Count";
[Route("")]
public IActionResult Index()
{
var counter = Counter++;
return Content($"I have counted to {counter}. " + DateTime.Now + " / " + HttpContext.Session.Id + " / " + Request.Headers["Connection"]);
}
private int Counter
{
get
{
return HttpContext.Session.GetInt32(CountKey) ?? 1;
}
set
{
HttpContext.Session.SetInt32(CountKey, value);
}
}
}
}
from session.
Ah. The response has a content-length so the client can disconnect as soon as it gets the last byte, which is before the session gets committed. Kestrel's client disconnect notice triggers, which triggers RequestAborted, which prevents the session from being committed.
This appears to be an order of operations bug in Kestrel. The complete request has been received and the complete response has been sent so if the client disconnects then it's out of scope of the request and it should't trigger RequestAborted. I'll move this issue to the Kestrel repo.
Workaround: call session.CommitAsync() when you're done modifying the session.
from session.
This issue was moved to aspnet/KestrelHttpServer#2195
from session.
After some discussion we've decided to change both Session and Kestrel. Session will no longer depend on RequestAborted for commits, only it's normal timeout.
from session.
This issue was moved to dotnet/aspnetcore#2395
from session.
Related Issues (20)
- Remove obsolete options APIs HOT 3
- Update session to configure DistributedMemoryCache options by default HOT 3
- Add logging scope for session HOT 2
- Random "Accessing expired session" warning HOT 4
- Error closing the session with .net 2.1.0-preview1 HOT 12
- Any plans for maximum session size property? HOT 2
- [1.1.4] Flaky test: SessionTests.SessionLogsCacheRefreshException HOT 6
- System.OperationCanceledException at Microsoft.Extensions.Caching.Redis.RedisCache+<RefreshAsync>d__25.MoveNext HOT 4
- cant access Session in other API HOT 5
- Error closing the session HOT 1
- [Patch 2.0.x] Downgrade cancellation logs HOT 1
- Add EventSource/EventCounter tracing and metrics for Session HOT 1
- Session cannot be re-loaded HOT 8
- Determine if the session cookie is considered essential HOT 1
- THIS ISSUE TRACKER IS CLOSED - use the Home repo issue tracker
- Session OnStart and Session OnEnd HOT 8
- How to get number of session HOT 3
- Re-initialize Session middleware from controller HOT 2
- How to add a custom session in .net core? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from session.