Reputation: 12059
Background: Writing a websocket. Works fine in Chrome. Single connection. Works fine in Firefox, but it makes two connections, and I have no clue why. Same javascript, same webpage, same socket server.
Client side JS:
var ws;
doWebSocketSetup();
function doWebSocketSetup(){
console.log('Connecting...');
ws=new WebSocket('ws://mysocketserver.com:9300/demo');
ws.onopen=function(){
console.log('Connected!')
socketSend('connect',sessionStorage.user);
if(!sessionStorage.announce){
socketSend('login',sessionStorage.user);
sessionStorage.announce=true;
}
socketSend('view',window.location.href);
setTimeout(function(){
processQueue();
},100);
}
ws.onmessage=function(e){
if(e.data!='ok'){
$.msg(e.data,{header:'Server Message',live:10000});
console.log('Server: '+e.data);
}
processQueue();
}
ws.onclose=function(){
console.log('Disconnected');
}
}
var sendQueue=new Array();
function socketSend(action,data){
var payload = new Object()
payload.action = action
payload.client = sessionStorage.user
payload.data = data
sendQueue.unshift(payload);
}
function processQueue(){
if(sendQueue.length==0)
return;
var payload=sendQueue.pop()
console.log('Sending: '+JSON.stringify(payload));
ws.send(JSON.stringify(payload))
}
And now the server console output on Firefox:
2012-10-18 20:58:53 [info] [client 68.99.226.57:53079] Connected 94e568176299729fa8669c512fdb107d
2012-10-18 20:58:53 [info] [client 68.99.226.57:53080] Connected 457eb971eabaeba6b6afd637755ce53c
2012-10-18 20:58:53 [info] [client 68.99.226.57:53080] Performing handshake
2012-10-18 20:58:53 [info] [client 68.99.226.57:53080] Handshake sent
2012-10-18 20:58:54 [info] [client 68.99.226.57:53080] _actionConnect
2012-10-18 20:58:54 [info] [client 68.99.226.57:53080] _actionView
2012-10-18 20:58:58 [info] [client 68.99.226.57:53079] Disconnected - 94e5681762 99729fa8669c512fdb107d
And on Chrome:
2012-10-18 21:09:17 [info] [client 68.99.226.57:53161] Connected 3906f16fa4037cbb08a8a5d1d6094cea
2012-10-18 21:09:17 [info] [client 68.99.226.57:53161] Performing handshake
2012-10-18 21:09:17 [info] [client 68.99.226.57:53161] Handshake sent
2012-10-18 21:09:17 [info] [client 68.99.226.57:53161] _actionConnect
2012-10-18 21:09:17 [info] [client 68.99.226.57:53161] _actionView
You see on Chrome a SINGLE connection, and the appropriate handshake and actions are called. On Firefox, you two connections at the exact same time, one handshakes and performs the actions (which does what it is intended on the browser), but the second connection is kicked after 5 seconds. Is this just a Firefox thing? I am not showing two connections in Firebug, just the single connection. If it is just a Firefox thing, I can live with it as the correct data does get sent and received, but I will furrow my brow at them if this is the case.
Upvotes: 1
Views: 794
Reputation: 1
I've got similar issue using actual FF version having enabled dns over https in browser settings behind local firewall. Websocket server's ip was resolved by the local router's dns. First connection failed during resolving process. The second succeed. The same website resolved by a global dns outside firewall worked fine.
Upvotes: 0
Reputation: 73147
This is a bug in Firefox 15 where it creates a speculative connection that it never uses (and in fact can't because it is a WebSocket connection rather than an HTTP connection).
It is fixed in Firefox 16.
Upvotes: 2