LearnBoost/socket.io — Issue #763: Cross domain socket.io connection fails
Author: kumarnmanoj
Created: 2012-02-24 07:46:09+00:00
State: open

Hi,

We are working on live streaming app based on socket.io. We are running 2 socket.io instances behind a HAPROXY balancing with source based routing.

If socket.io runs in the same domain (in content provider domain) with HAPROXY everything is fine...
Now socket.io server is running in a different domain.

The initial handshake request is successfull but after that connection is not established. Happens only in cross domain socket.io connection.

Intial handshake details

Request URL:http:///socket.io/1/?t=1330062135129

Request Method:GET

Status Code:200 OK
Request Headersview source

Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Host:

Origin:
Referer:

User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11
Query String Parametersview URL encoded

t:1330062135129
Response Headers

Access-Control-Allow-Origin:*

Connection:close
Content-Type:text/plain

Transfer-Encoding:chunked

Response to the above : 10163290772037531673:15:25:websocket,htmlfile,xhr-polling,jsonp-polling

After that it is trying to connect via websocket

Request URL:ws:///socket.io/1/websocket/10163290772037531673

Request Method:GET

Status Code:101 Switching Protocols
Request Headersview source

Connection:Upgrade

Host:
Origin:http://

Sec-WebSocket-Key:vrrbgXaUMXvjgrgJVhxBLg==

Sec-WebSocket-Version:13

Upgrade:websocket
(Key3):00:00:00:00:00:00:00:00
Response Headers:

Connection:Upgrade

Sec-WebSocket-Accept:An5vqvx1hO1o7uvY+VdbXXRChu8=

Upgrade:websocket
(Challenge Response):00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00

But in the client side connection event is not fired.

Server side we are getting connection event but followed by disconnection event.

The above sequence continues. handshake then websocket connection/ handshake then websocket connection not ending after a while we are getting the following thing in chrome

socket.io.js:2323Uncaught Error: INVALID_STATE_ERR: DOM Exception 11
WS.sendsocket.io.js:2323
Transport.packetsocket.io.js:1389
Socket.packetsocket.io.js:1739
SocketNamespace.packetsocket.io.js:2053
resetsocket.io.js:1925
maybeReconnectsocket.io.js:1950
EventEmitter.emitsocket.io.js:632
Socket.onConnectsocket.io.js:1830
Transport.onConnectsocket.io.js:1350
Transport.onPacketsocket.io.js:1306
Transport.onDatasocket.io.js:1286
WS.open.websocket.onmessagesocket.io.js:2301
:1WebSocket is closed before the connection is established.

We are using socket.io 0.8.7

This happens across all the chrome/firefox/safari irrespective of the versions.