Disconnecting returns different reasons for each browser and transport.
On disconnect, the value for reason for closing changes for every browser changes. The following are the results. polling websockets google chrome - Transport Error Transport Close IE10 - Ping Timeout Transport Close Safari - Ping Timeout Transport Close
On checking in the logs (client-side), this error is shown right before the call on the disconnect() method.
Error: xhr poll error {type: "TransportError", description: 0, stack: (...), message: "xhr poll error"}
Why is this so?
Thank you for your report! Can you explain how to reproduce this?
I might not be able to give the complete details on how to reproduce this as I was upgrading from 0.9 to 1.2.1 of someone else's codes.
Anyhow, all I did was this:
1.) Connect to a socket via polling. 2.) Immediately disconnect while it is continuously polling.
I know its kind of basic but that is all I can figure out from the codes.
Thanks but we need more details. I tried the following but couldn't reproduce.
var socket = io({ transports: ['polling'] });
socket.on('connect', funtion() {
socket.on('disconnect', function(reason) {
console.log(reason); // => "io client disconnect"
});
socket.disconnect();
});
for opening:
SocketIOWrapper(host, details) {
var options = {
'forceNew': true,
'reconnection': false,
'timeout': 10000,
'flash policy port': 843,
'auto connect': true //left as is because changing to autoConnect returns a weird error.
};
if (details && details.transports) {
//change xhr-polling or jsonp-polling to polling.
if (details.transports[0] === 'xhr-polling' ||
details.transports[0] === 'jsonp-polling') {
details.transports[0] = 'polling';
}
io.transports = details.transports;
}
// merge options and details (passed from webpage).
for (var key in details) {
if (options.hasOwnProperty(key)) {
//added to change "resource" key to "path".
if (key === "resource") {
options["path"] = "/"+details["resource"];
} else if (key === "transports") {
//updated to change transport value to 'polling' when
//'xhr-polling' or 'jsonp-polling' is selected.
options[key] = details[key];
if (details["transports"][0] == "xhr-polling") {
options["transports"][0] = "polling";
} else if (details["transports"][0] == "jsonp-polling") {
options["transports"][0] = "polling";
options["forceJSONP"] = true;
options["jsonp"] = true;
}
} else {
options[key] = details[key];
}
}
}
this.options = options;
this.namespace = io.connect(host, options);
if (this.options['auto connect']) {
this.status = qr.CONNECTING;
this.setHandshakeTimeout();
}
}
and closing:
SocketIOWrapper.prototype.close = function() {
if (this.status === qr.OPEN) {
this.status = qr.CLOSING;
this.namespace.disconnect();
}
return this;
};
it seems like in chrome, when the connection is cut while polling, it sends and error while internet explorer does nothing but wait for another ping until it times out.

here's the logs when the error occurs
Thank you for the logs. I could reproduce that the disconnected reason is "transport error" on chrome when I shutdown server.
I found that this happens because xhr.status is 0 on this situation, and I'm thinking this is not a bug now since how xhr works depends on browser.
What kind of problem do you have because of this issue?
Chrome doesn't seem to be an issue when disconnecting. However, Safari is rather problematic given the following scenario:
1.) After login, screen connects via polling. 2.) Open a link (Safari opens it in a new tab) and safari opens another transport (via polling). 3.) Wait for first transport to close. 4.) When first transport is closed, close the new tab and return to first screen. 5.) The frist screen opens another transport. 6.) 2nd transport closes via timeout.
With this scenario, websocket seems to work completely fine and reconnects the first screen's transport but polling doesn't.
Umm sorry, I couldn't understand the case. Could you explain the scenario and how different reasons cause any problems to you again?
In Safari, when you open two tabs with different connections, focusing on a tab will disconnect the other with a ping timeout. No problem there. (Screen A: disconnected after timeout, Screen B: connected).
Closing Screen B will result to a disconnect (reason: server namespace disconnect) when using websockets and disconnect (reason: ping timeout) when using polling.
What happens is that there is a difference in behavior when using either of the two:
→In websocket, it immediately disconnects Screen B before it creates another connection for Screen A after 1 min or so (I have yet to discover why it takes such a long time to reconnect). →In polling, it creates a new connection (presumably to screen B) while Screen B's connection is waiting to be disconnected after timeout.
This results in Screen A not having a connection at all. Or so I think.
Umm basically each tab has a different context, thus they would not affect each other. Anyway I will try to reproduce the problem later. Thx again for your report.
they may have a different context but when session is involved, does it change things?
In Safari, when you open two tabs with different connections, focusing on a tab will disconnect the other with a ping timeout.
I tried to reproduce the above case but couldn't. I think this issue is the problem of your app rather than socket.io since session of socket.io is only for keeping connections.
It may probably be so but allow me to re.explain the scenario as it seems that I too have problems understanding a few days back.
For now, let us stick to chrome. Connecting on either transport has no problems but when I disconnect while they are polling, they seem to be showing completely different behaviours.
Polling Logs

Websocket Logs

Server side, they are disconnected just fine with reasons (transport error for polling and transport close for websockets) fine.
But I do agree with you that it is probably my codes that's causing this error.
Closed for now. Feel free to reopen if you still have the problem, thx.