htmlfile ActiveX very abscure problem (not the usual disconnect

htmlfile ActiveX very abscure problem (not the usual disconnect

am 17.04.2008 13:00:03 von 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/t hread/e337ac03d0c9f13f#
2) http://cometdaily.com/2007/11/18/ie-activexhtmlfile-transpor t-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("");

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; charset=utf-8\">";
print "";
print "";
print "";

while( GetSomeData($dat) ) //is a well behaved waiting function
{
print "\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.

Re: htmlfile ActiveX very abscure problem (not the usual disconnect

am 21.04.2008 10:51:42 von 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!!!!!

Re: htmlfile ActiveX very abscure problem (not the usual disconnect problem)

am 21.04.2008 22:33:14 von Neredbojias

On 21 Apr 2008, JT wrote:

> 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!!!!!

Well no wonder there's a problem! Why on earth did they put a
gynecologist in Internet Explorer in the first place?

--
Neredbojias
http://www.neredbojias.com/
Great sights and sounds

Re: htmlfile ActiveX very abscure problem (not the usual disconnect

am 23.04.2008 15:32:30 von 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 ;)

Re: htmlfile ActiveX very abscure problem (not the usual disconnect problem)

am 23.04.2008 19:36:28 von Neredbojias

On 23 Apr 2008, JT wrote:

> 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 ;)

Yup, 'tis true. I know some javascript, but I always though Ajax was some
homo-looking Steve-Reeves-type guy who liked to run around in a loin cloth
in 'B' gladiator movies. -Or, of course, the foaming cleanser.

Anyway, I'm not sure I know what pseudo streaming is, but ie seems to play
music and vids okay.

--
Neredbojias
http://www.neredbojias.com/
Great sights and sounds