0

I've just discovered that ASP.NET MVC controllers 'lock' the session when each call to the controller is made. So, if your call takes 1 minute to complete, then all calls get queued up until that 1 minute call finishes. Also - if the browser tab closes, then the call never finishes and the session remains locked forever - which means the user can't use the system again until the session dies. To me this seems like a huge problem and I am surprised I haven't noticed before.

I only store a couple of things in the session so I would like to just lock it during the rare moments that I update those things, but this doesn't seem possible. It seems to be all or nothing - either it completely locks it or it is read only.

Does anyone have advice on how I can get around this?

Thanks

BuckBuchanan
  • 198
  • 13
  • 2
    I don’t think that’s how it works. Why would the locking stay if a connection breaks? That would be a huge problem and nobody could use sessions. Which version are we talking about here? – Sami Kuhmonen Oct 07 '21 at 07:51
  • What exactly makes you think Sessions would work so terribly bad? This description makes absolutely no sense – Camilo Terevinto Oct 07 '21 at 08:30
  • 2
    Possible duplicate https://stackoverflow.com/questions/4318965/asp-net-session-request-queuing – Hans Kesting Oct 07 '21 at 09:22
  • Use Async `Action`. And I think that is not how session works. – Rahatur Oct 07 '21 at 11:16
  • If you open the session table (ASPStateTempSessions) you will see there is a column - Locked. When this is 1 the session is locked. You can see this going to 1 as soon as a controller is called, and it doesn't go back to 0 until that call finishes. Connection breaking can be reproduced by a long running query. After the query starts close the browser tab. Notice the Locked column gets stuck at 1. Open a new browser - see that the application has hung. The page will not load. But - if you then manually set the Locked column back to 0 then everything springs back to life. Try it before comment! – BuckBuchanan Oct 07 '21 at 22:42
  • @HansKesting thank you - yes this is someone else reporting exactly this problem. Unfortunately no solution – BuckBuchanan Oct 07 '21 at 22:50
  • @Rahatur Async actions have got nothing at all to do with this. The session is a completely other thing which works exactly as I have described. – BuckBuchanan Oct 07 '21 at 22:52

1 Answers1

0

So, basically I ended up just making my own session manager, and this has solved the problem.

To me it looks like the ASP.NET Session manager isn't really fit for purpose any more. It might have been in the olden days, but now with multiple ajax calls being common, and the fact that a long running operation can leave the site completely frozen I think my advise to anyone would just be to avoid using it altogether.

BuckBuchanan
  • 198
  • 13
  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 13 '21 at 05:52