473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

AJAX "crashes" IE on close of Window.

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
5 13882
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: f.ruecker | last post by:
Hey Folks, I hope you'll be nice to me and let this post go through even know its mysql and not directly php. But of course my script is php. The problem is, that my Table (1,8 MIO entries/100...
24
by: sinister | last post by:
After doing a websearch, it appears that it's OK to omit the "http:" to form a relative URL. Are there any pitfalls to this? For example, if there is a page http://www.domain1.com/page1.html...
6
by: (Pete Cresswell) | last post by:
I'm makeing a little DB to help manage high school class reunions. One feature I'm trying to implement is "Friends". e.g. Fred Smith is a friend of Joe Jones and Bill Anderson. We record...
5
by: _BNC | last post by:
I've converted " byte" to "byte *" at times, using 'unsafe' and fixed { .... }, but the reverse does not seem to work. In this case, a C++ DLL returns a byte * and a length. What is the best...
7
by: Simon Verona | last post by:
I have a problem in my application which I believe is due to open handles.. . The symptom that users report is that after they have been using the application for a while, it will randomly just...
3
by: Jerry | last post by:
I have created an application using wxPython and compiled it using py2exe. When I put setup(console=) in my setup.py file, the resulting application runs just fine. But when I change it to...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
1
by: Toni | last post by:
Hello! I have a problem that I hope someone could help me with. Recently a web application was ordered from a software developer and installed on the server of my working place. This application...
9
by: andrew.smith.cpp | last post by:
hi, whts the difference between the std::endl or "\n" ? because both do the same work Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.