htmlfile ActiveX very abscure problem (not the usual disconnectproblem)

J

JT

Hello, here is a really obscure problem (i think!) which is bound to
get the mind juices pumping!!

Basically i am implementing a Comet style methodology for streaming
data to the client over long lived http connections (apache & php
configured to support this). I have done my research and looked at the
following good articles/ initiatives:
1) http://groups.google.com/group/orbited-users/browse_thread/thread/e337ac03d0c9f13f#
2) http://cometdaily.com/2007/11/18/ie-activexhtmlfile-transport-part-ii/
3) I have also looked at how meteorserver (http://meteorserver.org)
works. BTW hats off to the meteoserver team, job well done i must
say..

OK I have the streaming working nicely (i am using IE 7), it will
stream for hours on end no problem if for what ever reason we
disconnect i have some nice reconnect logic in place; eventually i
will also implement heartbeats etc..

The data that i am streaming i am displaying in a Grid. I have created
a very nice Grid class using DIVs, i also use mouse events to detect
DIV boundaries so the user can resize the Grid or individual columns
as they see fit etc..

As soon as the user clicks on a column to resize the streaming stops.
However neither is the onLoad event called in the iframe html body or
neither is the tcp/ip socket to the server broken. I confirm this by
looking at the apache logs which tell me that the connection is still
open. Further to that, according to Ethereal (WinPCAP) the server is
still flushing script tags to the client!! Yet those script tags are
not being executed and the onLoad method has not been called!! Then
after this the Web Server (Apache 2.2 compiled on Win32) becomes
completely unusable, and for sometime it will not accept anymore
connections on it's listening port, then it seams to recover itself
(when the client is killed) and sometimes it cannot recover and dies
with a Segmentation Fault!!!

My code is as follows:

function initMarketStream()
{
try
{
htFile = new ActiveXObject("htmlfile");
htFile.open();
htFile.write("<html><iframe src=\""+url+"\"></iframe></html>");

htFile.parentWindow.cb = function(resp)
{
window.status="r " + (new Date()) + " " + resp;
handleMarketStream(resp);
}

htFile.parentWindow.rc = function()
{
htFile= null;
if(typeof CollectGarbage == "function") CollectGarbage();

window.status="recon at: " + (new Date());
setTimeout( 'initMarketStream();', 100);
}

htFile.close();
setInterval( function () {}, 10000);
}
catch(e)
{
}
}

The html i send to the iframe looks like this:
<?
print str_repeat(" ",1060);
print "<html><head><meta http-equiv=\"Content-Type\" content=\"text/
html; charset=utf-8\">";
print "<script>window.onError = null;</script>";
print "</head>";
print "<body onload=\"parent.rc();\">";

while( GetSomeData($dat) ) //is a well behaved waiting function
{
print "<script>parent.cb(\"".($dat)."\");</script>\n";
ob_flush();
flush();
}
?>

The colomn resize logic is basically some javascript handlers on Mouse
Down/Up/Move events which manulplate the elements/ objects in the
document:

Basically the resize works by a handler on the highest bubbled
mousemove event which detects when a DIV boundry exists and the resize
the DIV in accordance with the mouse cordinates if the button is
prest. The javascript routines which are used include: childNodes,
tagName, offsetWidth/ Height etc.., cursor, style objects, parentNode,
getAttribute, event object, we also use some global variables to
mentain state..

I really can't see how manipulating the DOM on the main document,
causes the ActiveX htmlfile to go into a deep unknown void which
nearly brings the web server to its knees!!!

Sorry for the long post guys, but any ideas would be appreciated.
 
J

JT

sighhhh, a few hacks later i think i have this sust, so thought i'd
post my findings etc..
The basic problem was with the Garbage Collector.

the GC in IE appears to collect objects that still have one or more
references to them!! as follows:

var _myObj = false; //global scope

function initMe()
{
_myObj = new ActiveXObject("htmlfile");

.... //set up the activex object appropriately.

setTimeout( function() { CollectGarbage(); window.status = "gc
done"; }, 100);
}

the above code demonstrates that the GC does indeed clean up the
activex object, when clearly it shouldn't, because un-commenting the
timeout makes the code work for atleast a few minutes, however with
the GC timeout in place the stream never gets up and running.. so on
that note we learn (this is purely my opinion), that the IE GC doesn't
keep a reference count of all allocated objects on the heap (like any
self respecting GC)!! A hack which solves this problem and keeps my
connection a live for long periods is to add this line of code to the
end of the initMe function:

setInterval( function () { var __x = ((_myObj ) && (typeof
_myObj .parentWindow == "object" )) }, 100);

or basically some interval which is constantly reading the reference
to the parentWindow. Now an improvement on this will be to test the
value of __x and if it is false clear all previous xyz and call initMe
in some timeout.

However interestingly enough when the GC purges the ActiveX object,
any further attempts by that instance of the IE binary to refresh/
reload any webpage on that same webserver fails!! the socket
connection hangs on some linger state!!
And looking at the Apache logs we see the request from that ActiveX
htmlfile is still alive, and when we close/ kill that instance of IE,
do we then see that connection break and according to Apache customlog
the connection was aborted in an untimely manner!!

I would love to meet the person/ team who wrote the GC for IE scrips/
DOM!!
Or better still i would love to be introduced to the IE QA Testing
team!!!!!
 
J

JT

lol, i c the world of ajax hacking is new to you Neredbojias.
Sadly the reason we need to use all these dirty hacks is because IE
resists http pseudo streaming so much ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top