1.3.3 breaks on Safari/Midori - Webkit issue?
Hi there,
I recently upgraded to v1.3.3 from v1.3.2 and Safari and Midori clients are broken now. The initial connect event fires, but the websocket gets stuck in some weird state where it's connected but not really. I get the following information by enabling the client debug:
[Log] socket.io-client:socket emitting event [object Object] +3ms ([native code], line 0)
[Log] engine.io-client:socket flushing 1 packets in socket +19ms ([native code], line 0)
[Log] engine.io-client:websocket websocket closed before onclose event +1ms ([native code], line 0)
...shortly after the socket connects. It is completing the connection and I can send a few events to it before it breaks, but I'm not sure what exactly is causing the breakage. Did 1.3.3 bump the engine.io version?
Downgrading socket.io to 1.3.2 resolves the issue. It is reproducible. Every time I load the page on a server running 1.3.3, it breaks on Safari, and every time I load the page on 1.3.2 it works.
I'd be happy to test things or provide a simple demo server if need be.
I should note that in particular, this happens when you explicitly set transports to ['websocket', 'polling'] on the client.
app.js
var io = require('socket.io')(3000);
io.on('connection', function(socket) {
socket.on('ping', function() {
console.log('got ping from ' + socket.conn.remoteAddress);
socket.emit('pong');
});
});
index.html (serve with python2 -m SimpleHTTPServer or your own webserver)
<html>
<body>
<h1></h1>
<script src="http://localhost:3000/socket.io/socket.io.js"></script>
<script>
var socket = io('http://localhost:3000', { transports: ['websocket', 'polling'] });
var pongs = 0;
socket.on('pong', function() {
pongs++;
document.getElementsByTagName('h1')[0].innerHTML = pongs + ' pongs';
});
setInterval(function() {
socket.emit('ping');
}, 1000);
</script>
</body>
</html>
Visiting the page in Midori works as expected with socket.io 1.3.2; on 1.3.3 no pings are reported on the server and no pongs are received by the client.
Do you get any error events on the socket object ?
No error events are fired. This is a more complete debug output:
[Log] socket.io-client:url parse http://localhost:3000 +0ms ([native code], line 0)
[Log] socket.io-client new io instance for http://localhost:3000 +0ms ([native code], line 0)
[Log] socket.io-client:manager readyState closed +0ms ([native code], line 0)
[Log] socket.io-client:manager opening http://localhost:3000 +1ms ([native code], line 0)
[Log] engine.io-client:socket creating transport "websocket" +0ms ([native code], line 0)
[Log] engine.io-client:socket setting transport websocket +5ms ([native code], line 0)
[Log] socket.io-client:manager connect attempt will timeout after 20000 +11ms ([native code], line 0)
[Log] socket.io-client:manager readyState opening +2ms ([native code], line 0)
[Log] engine.io-client:socket socket receive: type "open", data "{"sid":"acjzpAJvQxt9kZSLAAAA","upgrades":[],"pingInterval":25000,"pingTimeout":60000}" +53ms ([native code], line 0)
[Log] engine.io-client:socket socket open +4ms ([native code], line 0)
[Log] socket.io-client:manager open +54ms ([native code], line 0)
[Log] socket.io-client:socket transport is open - connecting +0ms ([native code], line 0)
[Log] engine.io-client:socket socket receive: type "message", data "0" +6ms ([native code], line 0)
[Log] socket.io-parser decoded 0 as [object Object] +0ms ([native code], line 0)
[Log] socket.io-client:manager writing packet [object Object] +949ms ([native code], line 0)
[Log] socket.io-parser encoding packet [object Object] +944ms ([native code], line 0)
[Log] socket.io-parser encoded [object Object] as 2["ping"] +5ms ([native code], line 0)
[Log] engine.io-client:socket flushing 1 packets in socket +957ms ([native code], line 0)
[Log] engine.io-client:websocket websocket closed before onclose event +7ms ([native code], line 0)
[Log] socket.io-client:manager writing packet [object Object] +1s ([native code], line 0)
[Log] socket.io-parser encoding packet [object Object] +994ms ([native code], line 0)
[Log] socket.io-parser encoded [object Object] as 2["ping"] +3ms ([native code], line 0)
[Log] engine.io-client:socket flushing 1 packets in socket +990ms ([native code], line 0)
[Log] engine.io-client:websocket websocket closed before onclose event +5ms ([native code], line 0)
If it helps you out, midori is available for a variety of OSes and seems to display the same behavior as Safari (only available on OS X) for this particular issue.
This is super useful, thanks
Ahh... this is why I can't get things working. Same problem here.
Are there any other browsers that this happens on? Midori crashes for both my Windows and Ubuntu environment. (I've tried using Opera, Konqueror, and was unsuccessful on Vmplayer with Safari)
@aaandrew The issue also occurs for me in Epiphany.
Mobile Safari
Don't know why but it looks permessage-deflate was accidentally included on socket.io.js.
https://github.com/Automattic/socket.io-client/commit/3c00f970b5f07e204f2e2163ce874e638f487134
@rauchg I think we should rebuild it and release a new version anyway.
npm was getting engine.io-client from a local npm link instead of the version specific in package.json. Very strange behavior. 1.3.4 should address this.
Confirmed working in Midori, Epiphany, and mobile Safari on 1.3.4. Thanks.
🎉
I found this bug was because Safari throws TypeError when giving WebSocket#send the second argument as follows.
var ws = new WebSocket('http://localhost:3000');
ws.send('hi', undefined); // TypeError: Type error
https://github.com/Automattic/engine.io-client/blob/master/lib/transports/websocket.js#L159
I will create a PR for this.
Nice catch
On Mon Feb 16 2015 at 10:04:45 AM Naoyuki Kanezawa [email protected] wrote:
I found this bug was because Safari throws TypeError when giving WebSocket#send the second argument as follows.
var ws = new WebSocket('http://localhost:3000'); ws.send('hi', undefined); // TypeError: Type error
https://github.com/Automattic/engine.io-client/blob/master/lib/transports/websocket.js#L159
I will create a PR for this.
— Reply to this email directly or view it on GitHub https://github.com/Automattic/socket.io/issues/2000#issuecomment-74549294 .