isAlive in sockets.js

View: New views
3 Messages — Rating Filter:   Alert me  

isAlive in sockets.js

by pc1oad1etter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What is the status of the isAlive function in sockets.js?
 
I saw this piece of documentation:
 
    // We really should call _transport.isAlive (?) but that is never reliable
    // (either always false or always true).
    // Experimentation shows that calls to available() or isAlive() will not
    // catch any problems with the connection until the javascript call
    // stack has completely unwound.
 
and I noticed that when rajeev posted a fix for some socket behavior, it included pulling out the isAlive call.  (http://mozdev.org/pipermail/jslib/2007-December/000917.html)  Should isAlive be used? 
 
I'm trying to debug some odd behavior  and am wondering if it is related to this.  Specifically, I have some code using sockets.js that shows this behavior:
when i run it repeatedly in jsliblive in Firefox, occasionally it hits a streak where after the socket.open is called, socket.isAlive() fails.  It might do this 7 times, and then I will have a streak where it works properly.
 
When we moved it out of Firefox and into a xulrunner app, it started failing on isAlive() every time. 
 
Any insight on the use of isAlive would be appreciated - and if you have any ideas about the weird bug described above, please chime in!
 
nick

_______________________________________________
Jslib mailing list
Jslib@...
https://www.mozdev.org/mailman/listinfo/jslib

Re: isAlive in sockets.js

by Pete Collins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> Any insight on the use of isAlive would be appreciated - and if you
> have any ideas about the weird bug described above, please chime in!
>
The problem is I didn't write the socket code and never use it so I need
to rely on developers who are using the code to send in their patches.

I can review/cleanup and check in ...

--pete

--
Pete Collins - Founder, Mozdev Group Inc.
www.mozdevgroup.com
Mozilla Software Development Solutions
tel: 1-719-302-5811
fax: 1-719-302-5813

_______________________________________________
Jslib mailing list
Jslib@...
https://www.mozdev.org/mailman/listinfo/jslib

Re: isAlive in sockets.js

by pc1oad1etter :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

For what it's worth, I found out what the problem was with my sockets.
 
I was calling socket.open() followed by a test for socket.isAlive() to see if the open worked - there is no return value from .open().  Often it would fail - so I tried to work around this by creating a loop that opens new sockets if the socket is not alive.  This often caught the problem when I ran it in the browser, but it failed much more often when I ran it in a xulrunner app.
 
Ultimately, it appears that isAlive() was getting called possibily before the work of socket.open() was completed.  By adding in a setTimeout() (even for just one millisecond), the problem is solved.  It appears that the .open() is working - it just doesn't complete in time if you test isAlive() immediately thereafter.
 
I don't have much experience with JavaScript (until now) but I know that some of it is pretty asynchronous, so I guess socket.isAlive may actually be getting called before socket.open even works.
 
So I don't have a fix to put in the code, just a note that if isAlive is called immeidately, it may not be accurate.  This is tricky to debug because if you set a breakpoint , then the error might not surface.
 
nick

On Sat, Feb 23, 2008 at 12:01 PM, Pete Collins <pete@...> wrote:

> Any insight on the use of isAlive would be appreciated - and if you
> have any ideas about the weird bug described above, please chime in!
>
The problem is I didn't write the socket code and never use it so I need
to rely on developers who are using the code to send in their patches.

I can review/cleanup and check in ...

--pete

--
Pete Collins - Founder, Mozdev Group Inc.
www.mozdevgroup.com
Mozilla Software Development Solutions
tel: 1-719-302-5811
fax: 1-719-302-5813

_______________________________________________
Jslib mailing list
Jslib@...
https://www.mozdev.org/mailman/listinfo/jslib


_______________________________________________
Jslib mailing list
Jslib@...
https://www.mozdev.org/mailman/listinfo/jslib