Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it supposed to work with socket.io ? #81

Closed
Marsup opened this issue Sep 19, 2013 · 7 comments
Closed

Is it supposed to work with socket.io ? #81

Marsup opened this issue Sep 19, 2013 · 7 comments

Comments

@Marsup
Copy link

Marsup commented Sep 19, 2013

Hi,

I'm having problems with socket.io (which is using websocket transport) since I replaced cluster with pm2.

It needs several attempts to maintain a stable connection, first few connections end prematurely with sometimes a few packets sent, then stabilize.

Chrome's frame log simply shows a Connection Close Frame (Opcode 8, mask) not much to see.
Server side socket.io logs show :

debug - authorized
info  - handshake authorized dKdKDeFGJqlvfiamHw8Y
debug - setting request GET /socket.io/1/websocket/dKdKDeFGJqlvfiamHw8Y
debug - set heartbeat interval for client dKdKDeFGJqlvfiamHw8Y
debug - websocket writing 7:::1+0
warn  - client not handshaken client should reconnect
info  - transport end (error)
debug - set close timeout for client dKdKDeFGJqlvfiamHw8Y
debug - cleared close timeout for client dKdKDeFGJqlvfiamHw8Y
debug - cleared heartbeat interval for client dKdKDeFGJqlvfiamHw8Y
debug - discarding transport

Am I the only one seeing this ?
I'm using node 0.8.25 and socket.io 0.9.16.

@Unitech
Copy link
Owner

Unitech commented Sep 21, 2013

Hey,

As you use multiple instances of the same script, socketio doesn't know how to handle proper routes to maintain the same connection between all instances.

You must configure properly Socket.io as explained here : https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

If you want to scale to multiple process and / or multiple servers you can use our RedisStore which uses the Redis NoSQL database as man in the middle.

Cheers

@Unitech Unitech closed this as completed Sep 21, 2013
@rodrigopolo
Copy link

This isn't working, I have an app that used socket.io 0.9.x instanciated as it is said in the examples, it doesn't work, so I updated the socket.io to version 1.0.x and I add the "passport.socketio" version 3.1.x to have session support, again, doesn't work even following the example as described on socket.io and as described on passport.socketio readme:

https://github.com/jfromaniello/passport.socketio

Both versions and implementations of socket.io worked great on a single instance, but when I used more than one instance the communication failed 99% of the time. the main difference between version 0.9.x and version 1.0.x is I actually receive an error from the client console (some times)

WebSocket connection to 'ws://WEBADDRESS/?EIO=2&transport=websocket&sid=v_jTVm7ppnMQp7V3AAAA' failed: Connection closed before receiving a handshake response

socket.io.js:4332

So, there is something happening between socket.io and pm2 that should be reviewed.

@zarkone
Copy link

zarkone commented Jul 27, 2014

👍 I have the same problems.

@jago86
Copy link

jago86 commented Jul 31, 2014

Any news about this problem? I have the same, if I start only one instance with PM2, my app works perfectly, but if I start more than 1 instance, the comunications crash, i see the error "Unable to connect Socket.IO client not handshaken".

@dickeylth
Copy link

I have the same problem too. At first I thought that something is wrong with my nginx config or socket.io error. Now it proves to be the cluster.

@Marsup
Copy link
Author

Marsup commented Sep 3, 2014

For the record I was wrong about the initial issue.

Node.js 0.10 cluster mode should distribute its queries to multiple processes, and at the time it didn't in my case, 0.12 changes that (good explanation there), but it seems PM2 did it.

PM2 doesn't do sticky connections (which is not his job, neither cluster's) so you have to use an adapter to store your sessions such as socket.io-redis so that multiple instances of your server can know about it.

@dickeylth
Copy link

@Marsup ,thank you for your explanation! I'll give it a try following your suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants