I had the same problem and it took me a while to figure this out. Few studies have explained that this is due to the fact that some of the transports, such as a lengthy survey, have to make several queries in order to establish the optimal connection. The requests have a state, therefore, if different consecutive requests are routed for different employees of the cluster, the connection fails.
On the page http://socket.io/docs/using-multiple-nodes/ there is a page that links to a custom cluster module called sticky-session that works around this: https://github.com/indutny/sticky- session
I really didn’t want to use it, because it basically ignores all the work that the node.js team invested in balancing TCP load behind the cluster module.
Since the Web Socket protocol requires only one connection, I managed to get around this by making websocket be the first and only transport. I can do this because I manage the client and server. For a public webpage, this may not be safe for you, as you need to worry about browser compatibility. In my case, the client is a mobile application.
Here is the JavaScript client code that I posted on my test page (again, the real client is a mobile application, so my web page is just help helping build and test):
var socket = io('http://localhost:8080/', { transports: [ 'websocket' ] });
Brandon Dec 07 '14 at 2:09 a.m. 2014-12-07 02:09 a.m.
source share