Socket.io 'Handshake' failing with cluster and sticky-session

≯℡__Kan透↙ 提交于 2019-12-06 08:53:33

@jordyyy : I was facing same issue after googling I have fond answer. Socket.Io handshaking task complete in more than one request and when you will run on sticky session it means you are using multiple process according to your core.

So handshaking request will distribute on different different process and they can't talk.(not IPC) (They are child process) and most of time connection will be failed/lost.(connection-disconnect event occurs frequently )

So what is solution ? Solution is socketio-sticky-session

Socketio-sticky-session, manage connection on IP based. So when you will request by any client then it will maintain ip address with respect process/worker. So further request will be forward to same process/worker and your connection properly stabilized.

And When you will use redies adapter then you can actually maintain socket connection data b/w all processes/workers.

For more information https://github.com/elad/node-cluster-socket.io (you need some patch on worker_index method, if your server is supporting IPv6)

Just knowledge bytes. :) :)

One more thing, you don't need to fork process. It will be done by sticky session.

This was super old and wasn't really answered when i needed it, but my solution was to drop this bad module and any other super confusing module and just use pub/sub with redis adapter. The only other step was to force transports to websockets, and if that bothers anyone then use something else. For my purposes my solution was simple, readable, didn't mess with the 'typical' socket.io api, and best of all it worked extremely well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!