I have a long running (4-10 second) MVC action that runs a report from an AJAX call. While it's running users can change the parameters and run something else, so I cancel the AJAX request before making another one.
So, for instance (example in jQuery but the problem happens regardless):
// If we have an active request and it's not complete
if(dataRequest && dataRequest.readyState != 'complete')
{
dataRequest.abort();
}
dataRequest = $.ajax(...);
Client side this appears to work fine, but the cancelled request is still running on the server. For instance if the report takes 10 seconds, and I cancel one and start the other then the second request takes 20 seconds.
I think this is due to the session level locking:
[If] two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished.
So the second request can't access the session until the first one finishes. Using asynchronous MVC actions doesn't seem to get around this as the action still needs to be able to make changes to the session.
Is it possible to stop one action and start the next without using AsyncController
or [SessionState(SessionStateBehavior.ReadOnly)]
?
If it isn't are both required?