8

Although the socket.io document said 'sticky session' can make socket.io work with node cluster. I just can't make it work.

I find pm2 had several issues opened against it, the closest solution I can find is this, "force to use websock option only", don't use sticky session at all.

Has anyone had any experience that makes node cluster work with socket.io?

------- update --------

I checked the other two sticky session implementations mentioned here, sticky-session vs socket.io-sticky-session node js library ! Which is better? , find 'sticky-cluster' can do the job.

Another lesson I learned is that sticky-session doesn't work well with pm2 cluster, e.g. confirm from https://github.com/uqee/sticky-cluster/issues/26. So don't use pm2 cluster mode when using socket.io(or use 'websocket' transport only).

The 'sticky-session' implementation mentioned in socket.io document actually works too. If anyone needs more explanation with code sample, please check here https://github.com/elad/node-cluster-socket.io !

I leave my question open because I still like to see if there are other inputs.

Qiulang
  • 10,295
  • 11
  • 80
  • 129

1 Answers1

0

I asked this question in 2017 when socket.io project had gone inactive for a while but since 2021 socket.io has been actively maintained again!

Its website now has 2 articles and the "official" answer to address this issue:

  1. https://socket.io/docs/v4/pm2/ talks about 3 solution for pm2, e.g. using websocket only w/o sticky-session or using @socket.io/pm2 w/ sticky-sesssion.

  2. https://socket.io/docs/v4/using-multiple-nodes/ talks about sticky-session with some multiple-nodes solution in more details, in a nutshell if you want long-polling fallback you will need sticky-session.

Qiulang
  • 10,295
  • 11
  • 80
  • 129