Deploying socket.io application to multiple nodes

I have an app on heroku that uses socket.io to communicate between server and client. Everything works perfectly. However, as soon as I scale my application to more than one dinar, I get multiple HTTP request errors:

can't establish a connection to the server at wss://***/socket.io/?EIO=2&transport=websocket&sid=Hky6IHdckNADdU_tAACm. socket.io.js:4520 The connection to wss://***/socket.io/?EIO=2&transport=websocket&sid=Hky6IHdckNADdU_tAACm was interrupted while the page was loading. socket.io.js:4520 can't establish a connection to the server at wss://***/socket.io/?EIO=2&transport=websocket&sid=kWymv6ItJHBcUybZAAAA. socket.io.js:4520 The connection to wss://***/socket.io/?EIO=2&transport=websocket&sid=kWymv6ItJHBcUybZAAAA was interrupted while the page was loading. socket.io.js:4520

Besides the load HTTP status 400 { code: 1, message: "Session ID unknown" }

My socket.io is using a redis adapter, so the state should be split correctly. I kind of confirmed this by connecting to redis and issuing the following command: PSUBSCRIBE socket.io#*

Since I can see data coming back and amplifying this channel, I am assuming that my socket.io redis adapter is working fine.

Does anyone know how to get socket.io to work with hero with more than 1 dyno?

+3


source to share


1 answer


You need sticky load balancing. Socket.io has a great article, so I'll leave them to explain the topic:



https://socket.io/docs/using-multiple-nodes/

0


source







All Articles