Chrome can't establish WebSocket connection

4,365 views
Skip to first unread message

lw9...@gmail.com

unread,
Mar 4, 2013, 10:27:46 AM3/4/13
to soc...@googlegroups.com
Hi,

On Chrome 24, I'm getting the console error "WebSocket is closed before the connection is established.", and sockjs falls back to xhr-streaming, but it is working fine with WebSockets on Firefox.
The server is sockjs-node (I get no errors on its side), and the client is roughly using the code:

window.onload = function() {
    var sock = new SockJS('http://localhost:9999/echo', null, {debug:true});
              sock.onmessage = function(msg) { ... }; 
}


Any ideas?

Thanks. 

hasher

unread,
Mar 4, 2013, 11:37:56 AM3/4/13
to soc...@googlegroups.com, lw9...@gmail.com
Have same, but only sometimes.

Marek Majkowski

unread,
Mar 4, 2013, 11:45:30 AM3/4/13
to lw9...@gmail.com, krzyszc...@gmail.com, soc...@googlegroups.com
I haven't seen this message yet. But, if I read it correctly, it
means that SockJS closed ws connection before it got established.

This is not unlikely. SockJS counts a RTT (round
trip time) from your browser to the server. It will then try different
transports and if they aren't working in a reasonable
time frame (usually X * RTT, with different 'X' for every transport),
they will be cancelled and SockJS will assume the transport
doesn't work and it will try another one.

This is good: SockJS will still work even if a transport takes
very long to establish. On the other hand it is possible that
the 'X' is wrong or that your network if flaky, and therefore
SockJS won't pick up the best transport always.

The 'X' for websockets is 2:
https://github.com/sockjs/sockjs-client/blob/master/lib/trans-websocket.js#L60

Which means that SockJS waits 2*RTT before assuming
that websockets don't work and moving on.

Marek

Marek Majkowski

unread,
Mar 5, 2013, 12:52:25 AM3/5/13
to Dark F, SockJS
(replying also to the list)

On Mon, Mar 4, 2013 at 8:35 PM, Dark F <lw9...@gmail.com> wrote:
> Interesting! Thank you, setting roundTrips to 5 seems to solve it. However,
> there is a noticeable 2- to 3-second pause while Chrome connects. Is this
> normal? Is it just something with Chrome? The weird thing is that even with
> RTT set to 2 or 3, it connects when the server is first run, but not after
> refreshing.

I have no clue why that might be the case. DNS? Weird proxy in the
way? Packets lost due to .... bad luck?

In any case, I'm happy to take a look at the pcap network
dump if you're able to prepare one. But please, make the pcap
contain only sockjs connections, and not the normal http traffic.

That means:
- close all your tabs, browsers, IM's, etc
- open a single tab with your website
- wait a sec.
- make sure sockjs client is not yet running
- open wireshark or tcpdump and make either of
them write pcap file to disk
- start sockjs connection
- wait a sec
- stop the pcap recording
- review the pcap file to make sure it only contains
relevant sockjs connections, not your ssh sessions
or unrelated http traffic.
- send me the pcap file.

Marek
Reply all
Reply to author
Forward
0 new messages