How to Treat Race Condition of Session in Web Application?

Posted by Morgan Cheng on Stack Overflow See other posts from Stack Overflow or by Morgan Cheng
Published on 2010-04-03T13:45:56Z Indexed on 2010/04/03 13:53 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

I was in a ASP.NET application has heavy traffic of AJAX requests.

Once a user login our web application, a session is created to store information of this user's state. Currently, our solution to keep session data consistent is quite simple and brutal: each request needs to acquire a exclusive lock before being processed.

This works fine for tradition web application. But, when the web application turns to support AJAX, it turns to not efficient. It is quite possible that multiple AJAX requests are sent to server at the same time without reloading the web page. If all AJAX requests are serialized by the exclusive lock, the response is not so quick. Anyway, many AJAX requests that doesn't access same session variables are blocked as well.

If we don't have a exclusive lock for each requests, then we need to treat all race condition carefully to avoid dead lock. I'm afraid that would make the code complex and buggy.

So, is there any best practice to keep session data consistent and keep code simple and clean?

© Stack Overflow or respective owner

Related posts about session

Related posts about consistency