Deploying a socket.io app in on multiple-nodes

637 Views Asked by At

I have an app on heroku that uses socket.io for server-client communication. Everything is working just fine. However, once I scale my app to more than 1 dyno, I get several 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

As well as a load of HTTP status 400 { code: 1, message: "Session ID unknown" }

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

Since I can see data traveling back and force on this channel, I am assuming my socket.io redis adapter is working fine.

Anyone know how to make socket.io work on heroku with more than 1 dyno?

1

There are 1 best solutions below

0
On

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

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