IE cannot call reconnect a second time
I am connecting with Socket IO in IE with:
sio = io.connect("http://testserver.local:8000"), { "reconnect": false, "max reconnection attempts": max_reconnects }
As soon as the server is down I call sio.socket.reconnect(); to manually reconnect.
If the server is up then it connects again. However, if the server is still down socket io stays forever in "sio.socket.connecting" and calling sio.socket.reconnect() will have no effect.
This seems to be for all IE transports. I tested 'flashsocket', 'xhr-polling', ' and jsonp-polling'.
Is there any way to work arround this or is there any fix?
Hi, I have the same problem. With any transport and any version of Internet Explorer (7, 8, 9), I don't receive any 'error' event when I try to connect to a socket.io server that is down, and when I connect and the server is becoming down while connected, I receive one 'disconnect' event, and then one 'reconnecting' event only. For any other browser I have tested (Chrome, Firefox, Opera), the socket.io client receives 'reconnecting' events continuously until server is up and running again. Did you find any workaround for this ? Nils
I also found this to be a problem. I looked in socket.io client file and traced it back to this code excerpt from the handshake function. line 1627.
if (this.isXDomain() && !io.util.ua.hasCORS) {
var insertAt = document.getElementsByTagName('script')[0]
, script = document.createElement('script');
script.src = url + '&jsonp=' + io.j.length;
insertAt.parentNode.insertBefore(script, insertAt);
io.j.push(function (data) {
complete(data);
script.parentNode.removeChild(script);
});
}
When IE tries to connect, it executes this code that appends a script tag in the head of the page to make the handshake to the server. If it loads the function that's pushed in the "io.j" array is called and the script tag is removed. If the server goes down in the middle of a session this is executed when reconnected. The problem is the callback function that's pushed in the array is never called if the script fails to load. I included the code block below before the push to "io.j"
script.onreadystatechange = function() {
if(this.readyState == 'loaded'){
self.connecting = false;
!self.reconnecting && self.onError('Server down or port not open');
script.parentNode.removeChild(script);
}
}
I tested in the different IE versions and found that if the script tag loads this.readyState never shows complete it just doesn't show a status other than loading, but the callback function is still executed from io.j so this has no effect on that. If the script fails to load because the server isn't responding this.readyState shows "loading" and then "loaded". So if the script shows "loaded" which means it failed then I set self.connecting to false and issue the error to trigger the reconnecting function again and it works just like the other browsers. It doesn't have effect on the other latest browsers (Chrome, Firefox, Opera, and Safari), but haven't checked any older ones except IE7 and IE8 which it works.
Is there a pull request associated with this change? I didn't see one
At the first load (for eg.: when the page loads), IE8 produces the error message "Server down or port not open", so I removed only that line:
!self.reconnecting && self.onError('Server down or port not open');
and now everything is ok!
By the way, thank you for your job!
Ugh, I'm surprised this is not properly fixed yet. I really, really appreciate this fix though. It's a pretty serious bug when you can't get IE to recover properly if the server happens to go away =|
This bug still happen? Can Anyone give me more info to reproducte it? I would like to try solve it :)
Guys, what about this issue? Is this solved in the new socket.io or not?
I've found this issue via some link on stackoverflow, so this is how I worked around this issue for socket.io 0.9.6 / ie8:
var _socket = io.connect();
...
_socket.on('disconnect', function(){
var interval = setInterval(function () {
if (_socket.socket.connected) {
clearInterval(interval);
} else {
_socket.socket.disconnect();
_socket.socket.reconnect();
}
}, 31000);
});
31 seconds interval is needed for the previous jsonp script inserted into document to time out, otherwise multiple connect events are triggered (multiple sockets get connected) when server becomes available.