0

Current setup: Node.js - 8.3.4 Socket.io - 2.0.4 Express - 4.15.4

I have recently run into an issue with running 2 concurrent instances of a middleware service that allows for socket.io connections. For traffic routing our company uses a combination of F5 and treafik, and I have been told that there is no way to guarantee a connection with the same server upon a new request. So when the front end connects to the middleware the first time, I get data from the socket connection. However, one refresh will likely cause several Session ID errors related to socket.io. This is because I am most likely being directed to the other server. I have been looking for a solution for this for a couple hours and this: https://www.npmjs.com/package/express-socket.io-session seems like a good possibility.

I feel like this is something that a lot of people have had to deal with. Can anyone give me their thoughts on what they have done to solve this issue? We currently use a Redis server to store user session data (auth related), I was thinking we could use it to store the Session IDs from socket.io then change the socket connection process to see if a session ID exists.

Thank you, Ryan

YeeP
  • 61
  • 1
  • 6
  • Possible duplicate of [Scaling Socket.IO to multiple Node.js processes using cluster](https://stackoverflow.com/questions/18310635/scaling-socket-io-to-multiple-node-js-processes-using-cluster) – Artur P. Mar 15 '18 at 20:54

1 Answers1

0

Did you try socket.io-redis module?

By running socket.io with the socket.io-redis adapter you can run multiple socket.io instances in different processes or servers that can all broadcast and emit events to and from each other.

If you need to emit events to socket.io instances from a non-socket.io process, you should use socket.io-emitter.

Also this can help: https://stackoverflow.com/a/18650183/7526159

Artur P.
  • 886
  • 4
  • 12