0

I start script below in Firefox to connects and sends text message to Websocket server installed on my local computer. Can you explain me why firefox sometimes opens two different sockets on server side to do this task? (on second socket there is send 0-lentgh message).

<html> 
  <head>
   <script>
    function ws_connect() 
    {

        ws = new WebSocket('ws://localhost:8080');
        ws.binaryType = "arraybuffer";
        ws.onopen = function(event)            
        {     
          var buf = new Uint8Array(2);
          buf[0] = "hi".charCodeAt(0);
          buf[1] = "hi".charCodeAt(1); // send message
          ws.send(buf.buffer);  
        }
        ...   
     }
   </script>
  <script> window.onload = function() {ws_connect();};</script>
  </head>

When I start script above , i get this expected data on server side(i print buffer, where first data from firefox is stored):

GET / HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pl,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
Origin: http://localhost:8383
Sec-WebSocket-Key: tEPJwmPYq9b2aMu7KfcpjQ==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket

When websocket handshake is ok, and script send "hi" massage, then firefox seems to open one more socket, send 0-length massage, and close it. (first socket is still open and i can use it.)

maciekm
  • 257
  • 1
  • 5
  • 28
  • 1
    Can you provide the HTTP requests that your backend is getting? – vtortola Sep 11 '14 at 14:25
  • @vtortola I provided HTTP requests, server gets from browser. Then server responds and websocket connection is established and data is send ("hi" massage). After that firefox seems to open another socket and close it in one momment. – maciekm Sep 11 '14 at 17:49
  • and that second socket has the same HTTP headers than this one? – vtortola Sep 11 '14 at 19:38
  • @vtortola second opened socket doesn't receive any HTTP headers or any data (0 - length buffer). It is opened and closed very fast. – maciekm Sep 11 '14 at 19:46

2 Answers2

2

https://bugzilla.mozilla.org/show_bug.cgi?id=786647

We issue a 2nd TCP socket connection in case the first one's SYN gets lost in transit. This is fairly standard now in browsers for HTTP (which is bootstrapping websockets). Not sure why Chrome isn't doing it--they are for regular HTTP IIRC

So apparently it is a common technique to ensure that a SYN packet gets to the target.

vtortola
  • 34,709
  • 29
  • 161
  • 263
-1

Quick guess - might this be an unexpected favicon request by the client How to prevent favicon.ico requests?

Community
  • 1
  • 1
GavinBrelstaff
  • 3,016
  • 2
  • 21
  • 39
  • 1
    Unlikely, OP seems to experience this on a websocket connection not for a favicon path. – Bergi Sep 11 '14 at 14:41