views:

2326

answers:

4

I have a web application and use ajax to call back to my webserver to fetch data.

Sometimes(at rather unpredictable moments, but it can be reproduced) IE hangs completely for 5 minutes(the window says Not Responding) and then comes back and the xmlhttprequest object responds with error 12002.

The way I can reproduce it is as follows.

  1. Open window(B) from main window(A) using button
  2. Window A calls synchronous ajax(PROC1) when button is clicked to open window B. PROC1 Runs file.
  3. New window(B) has ajax code(PROC2) and calls server asynchronous. Runs fine
  4. User closes Window B after PROC2 completed but before data is returned.
  5. In Main Window(a) user clicks button again. PROC1 runs again but now the send() call blocks for 5 minutes.

Please help. I've been looking for 3 days.

Please note: * I can't test it in firefox (the app is not firefox compatible) * I have to use synchronous calls (that's the way the app is constructed and it would take too much developer effort to rewrite it)

Why does this happen and how to I fix this?

+1  A: 

Winsock Error 12002 means the following according to msdn

ERROR_INTERNET_TIMEOUT

12002

The request has timed out.

Winsock is the underlying socket transfer object for XMLHTTP in IE so any error thats not in the HTTP error range (300,400,500 etc) is almost always a winsock error.

What wasnt clear from your question is wheter the same resource is being queried the 2nd time round. You could force a new uncached resource by appending:

'?uid=+'Math.random()

To the URL which might solve the issue.

another solution might be to attach a function to the "onbeforeunload" event on the window object to call abort() an any active XMLHTTP request just before the window B is closed.

Hope these 2 pointers solve your bug.

Martijn Laarman
+2  A: 

Thanks for answering Martijn.

It didn't solve my issues. I think what I'm seeing is best described on this website: http://bytes.com/groups/javascript/643080-ajax-crashes-ie-close-window

In my situation I have an unstable connection or a slow webserver and when the connection is too slow and the browser and the webserver still have a connection then freezes.

Jaap Geurts
+5  A: 

You're right Jaap, this is related to Internet Explorer's connection limit of 2. For some reason, IE doesn't release connections to AJAX requests performed in closed windows.

I have a very similar situation, only slightly simpler:

  • User clicks in Window A to open Window B
  • Window B performs an Ajax call that takes awhile
  • Before the Ajax call returns, user closes Window B. The connection to this call "leaks".
  • Repeat 1 more time until both available connections are "leaked"
  • Browser becomes unresponsive

One technique you can try (mentioned in the article you found) that does seem to work is to abort the XmlHttp request in the unload event of the page.

So something like:

var xhr = null;

function unloadPage() {
  if( xhr !== null ) {
    xhr.abort();
  }
}

Another option is to use synchronous AJAX calls, which will block until the call returns, essentially locking the browser. This may or may not be acceptable given your particular situation.

// the 3rd param is whether the call is asynchronous
xhr.open( 'get', 'url', false );

Finally, as mentioned elsewhere, you can adjust the maximum number of connections IE uses in the registry. Expecting visitors to your site to do this however isn't realistic, and it won't actually solve the problem -- just delay it from happening. As a side-note, IE8 is going to allow 6 concurrent connections.

Dave Lockhart
I used an abort solution to fix a very similar problem in IE8 with ajax and opening and closing windows. However, in order to abort and not lose the response I was looking for I had to use async:false in jQuery. This was fine in my case, but obviously not ideal. However, aborting did solve the empty new windows problem. See my comment in http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery for a little more detail.
Carvell Fenton
+1  A: 

By default Internet Explorer only allows two concurrent connections to the same website for download purposes. If you try and fire up more than this, I.E. stalls until one of the previous requests finishes at which point the next request will complete. I believe (although I could be wrong) this was put in place to prevent overloading websites with many concurrent downloads at a time. There is a registry hack to circumvent this lock.

I found these instructions kicking around the internet which alleviated my problems - I can't promise it will work for your situation, but the multi-connection limit you're facing appears related:

  1. Click on the Start button and select Run.
  2. On the Run line type Regedt32.exe and hit Enter. This will launch the Registry Editor
  3. Locate the following key in the registry: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
  4. Click on the Internet Settings Key.
  5. Now go to the Edit menu, point to NEW
  6. click DWORD Value
  7. Type *MaxConnectionsPer1_0Server* for the name of this DWORD Value.
  8. Double-click on the *MaxConnectionsPer1_0Server* key you just created and enter the following information: Value data: 10. Base: Decimal.
  9. When finished press OK.
  10. Repeat steps 4 through 9. This time naming the key MaxConnectionsPerServer and assigning it the same values as indicated in Steps 8.
  11. When finished press OK
  12. Close the Registry Editor.

Of course, I would use these in conjunction with the abort() call previously mentioned. In tandem, they should fix the issue.

BenAlabaster