javascript - Why would multiple simultaneous AJAX calls to the same ASP.NET MVC action cause the browser to block? -


a few days asked question:

why $.getjson() block browser?

i fire 6 jquery async ajax requests @ same controller action pretty @ once. each request takes 10 seconds return.

through debugging , logging requests action method notice requests serialised , never run in parallel. i.e. see timeline in log4net logs this:

 2010-12-13 13:25:06,633 [11164] info   - got:1156 2010-12-13 13:25:16,634 [11164] info   - returning:1156 2010-12-13 13:25:16,770 [7124] info   - got:1426 2010-12-13 13:25:26,772 [7124] info   - returning:1426 2010-12-13 13:25:26,925 [11164] info   - got:1912 2010-12-13 13:25:36,926 [11164] info   - returning:1912 2010-12-13 13:25:37,096 [9812] info   - got:1913 2010-12-13 13:25:47,098 [9812] info   - returning:1913 2010-12-13 13:25:47,283 [7124] info   - got:2002 2010-12-13 13:25:57,285 [7124] info   - returning:2002 2010-12-13 13:25:57,424 [11164] info   - got:1308 2010-12-13 13:26:07,425 [11164] info   - returning:1308 

looking @ network timeline in firefox see this:

alt text

both log sample above , firefox network timeline same set of requests.

are requests same action same page serialised? i'm aware of serialised access session object in same session, no session data being touched.

i stripped client side code down single request (the longest running one) still blocks browser, i.e. when ajax request completes browser respond link clicking.

what observe here (in chrome's developer tools) upon clicking on link when long running ajax request executing reports failed load resource error suggests browser has killed (or attempting kill , waiting?) ajax request:

alt text

however browser still takes age redirect new page.

are ajax requests asynchronous or sleight of hand because javascript single threaded?

are requests taking long work?

the problem occurs in firefox , ie well.

i changed script use $.ajax directly , explicitly set async: true.

i'm running on iis7.5, both windows 2008r2 , windows 7 flavours same thing.

debug , release builds behave same.

the answer staring me in face.

asp.net session state overview:

access asp.net session state exclusive per session, means if 2 different users make concurrent requests, access each separate session granted concurrently. however, if 2 concurrent requests made same session (by using same sessionid value), first request gets exclusive access session information. second request executes after first request finished.

annoyingly i'd skimmed paragraph couple of weeks ago not taking in full impact of bold sentences. had read "access session state serialised" , not "all requests, no matter whether touch session state or not, serialised" if requests came same session.

fortunately there work around in asp.net mvc3 , possible create session-less controllers. scott guthrie talks these here:

announcing asp.net mvc 3 (release candidate 2)

i installed mvc3 rc2 , upgraded project. decorating controller in question [sessionstate(sessionstatebehavior.disabled)] solves problem.

and of course typically found in stack overflow few minutes ago:

asynchronous controller blocking requests in asp.net mvc through jquery


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -