By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,052 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

AJAX "crashes" IE on close of Window.

P: n/a
It took me some time to find out when and why this happens.

When the window of Internet Explorer is closed with an AJAX call still
pending, something funny happens. Do it twice, and you will have to
restart the browser.

Here a little sample: http://truefriendz.de/iedos

The script on this site will open 5 test-windows one at a time.

The test-windows will issue an AJAX-Call. This call would only be
answered after 10 seconds, but the windows will be closed before
the answer arrives. (This is not a question of the window.close().
The same would happen if the close is issued by a user closing the
window)

Using IE6/w2k and IE7/vista (and assumedly other versions of IE)
the 3rd and following windows will appear without content. FireFox
performs perfectly well.

I found a workarround, which I regard as clumsy.

<body .... onAbort="cleanup();" onUnload="cleanup();">
function cleanup() { xmlHttp.abort();}

Demonstration here: http://truefriendz.de/iedos2

My findings so far: When a window with a pending AJAX-request
ActiveXObject("Microsoft.XMLHTTP") is closed, a TCP-socket remains
eternally in state close_wait. Check with netstat.

(It seems perfectly normal that sockets enter the state close_wait
(although if I understand the documents correctly this state should
only be entered by SERVERS),
and it seems that sockets can (normally) be reused succesfully from
this state. In "normal operation" such socktes do disappear after a
certain time)

My thoughts: Due to the fact that this Socket is still existing, IE
does
reuse it, but it does not work properly. These Sockets seem
to be damaged somehow.

Funny enough, I did not find any mention of this problem on the web.

Anyone, who can suggest a better, more elegant way to handle this?

Sorry for any mistakes, I did my very best, but I'm not a native
speaker.

May 7 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
So********@googlemail.com wrote:
It took me some time to find out when and why this happens.

When the window of Internet Explorer is closed with an AJAX call still
pending, something funny happens. Do it twice, and you will have to
restart the browser.

Here a little sample: http://truefriendz.de/iedos

The script on this site will open 5 test-windows one at a time.
Really? In my Internet Explorer 6 it merely says it is opening and
closing windows, but it does not open or close anything.

I do however get:

Line: 39
Char: 2
Error: Object doesn't support this property or method
Code: 0
URL: http://truefriendz.de/iedos/

....5 times.

<snip>

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 8 '07 #2

P: n/a
On May 8, 2:51 am, -Lost <maventheextrawo...@techie.comwrote:
The script on this site will open 5 test-windows one at a time.
Really? In my Internet Explorer 6 it merely says it is opening and
closing windows, but it does not open or close anything.
Well, it should, and it *does* on my computer. :)

Thank for giving it a try. The site where this script is hosted is
not mine, so I can do nothing about it *at this site*. But I
made a modified copy here:

http://sommerb.so.funpic.de/ajax/iedos.html

Perhaps this one wil do the Trick. Sorry, this site is not cpmpletely
ad-free, but this was the only PHP-enabled web space I could find
in short time.

I would be very grateful if anybody would have a look at this. I'm
completely at loss, since I found out that even the version *with*
calls to abort() of the AJAX does indeed throw a exception in
FireFox.

TIA

May 8 '07 #3

P: n/a
Just to give more informations:

<head>
var xmlHttp;

function ajax_call(){

//create AJAX.object
xmlHttp = new ActiveXObject(versions[idx]);

// Define onreadystatechange and issue call to very slow site
xmlHttp.open('GET', 'response-10s.php', true);
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert(xmlHttp.responseText);
}
};
xmlHttp.send(null);
}

function cleanup() {
if (xmlHttp) {xmlHttp.abort()}
}
</head>

<body onLoad="ajax_call();" onAbort="cleanup();" onUnload="cleanup();"
>
....

Without cleanup() this will do damage to Internet-Explorer
(sockets permanently in state close_wait) if the window
is closed with the AJAX still waiting for the response.

Obviously the Ajax doesn't "like" to go into non-existence
without a pending call beeing aborted.

I have very foggy ideas about an Ajax-object that enlists
itself for cleanup...

Somehow to add this cleanup into a chain of operations that are
done automatically on close of the window. I examined some
AJAX-Libraries, but found nothing like that in any of them.

May 8 '07 #4

P: n/a
So********@googlemail.com wrote:
I would be very grateful if anybody would have a look at this. I'm
completely at loss, since I found out that even the version *with*
calls to abort() of the AJAX does indeed throw a exception in
FireFox.
I do not have the time to peruse your code again, but I can tell you two
things.

1) Depending on your use of your XHR object, abort() is not necessary.
For example, calling the open() method twice on a single XHR object
will reset the object, its connection (what was previously opened/sent),
and will disconnect any event handlers.

2) Firefox does not like the abort() method. Most notably in cases of
use in the onreadystatechange event.

NOTE: About the above, it is essential to use abort() in Firefox when
canceling an XHR request, just not in the above mentioned event.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
May 8 '07 #5

P: n/a
So********@googlemail.com wrote:
>
When the window of Internet Explorer is closed with an AJAX call still
pending, something funny happens. Do it twice, and you will have to
restart the browser.
This sounds like a manifestation of a garbage-collection bug in IE.
When a document references javascript, and the javascript references
back to the document (which is pretty much all the time with AJAX)
then closing the document won't cause the javascript to be terminated.

Furthermore, IE has a very small limit on the number of connections
that it will allow to be simultaneously open to a given site. This
means that when your XmlHttp connections don't terminate, you quickly
run out of connections. This leaves you stuck until the XmlHttp
connections time out, which can take several minutes.

It's a pain in the ass. IE has had this bug for years. I don't know
if the newest version of IE still has the bug, but you have to plan
for the worst -- assume IE always has the bug.

See http://www.litotes.demon.co.uk/examp...finalizer.html
for more on the problem, and one possible solution.

Another technique which I've read about BUT NEVER TRIED is to use
different names for the server, so you increase the number of possible
connections. For example, supposedly "google.com" and "www.google.com"
will have separate connection pools even if they reference the same
site. The reason I never tried this technique is that it seems like
it'd take a lot of intricate site-specific engineering to make it
work reliably.
May 9 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.