Multi replica socket IO not connecting

ghoshpushpendu
TRIAL

4 months ago

I have react front end and node js backend.

In node js backend we are using socketio to expose websocket server along with redis adapter so the socket server can scale to multiple servers.

When there is a single server , everything is working properly but where there is multiple replicas in railway socket is not connecting with the below error message

onPacket transport.js:99

Socket.IO.Context.js:29:16

XHRPOSThttps://compiler-production-7afb.up.railway.app/socket.io/?EIO=4&transport=polling&t=vviblycj&sid=8hBsGeYA_IrY5q7LAAAS[HTTP/2 400 78ms]

GETwss://compiler-production-7afb.up.railway.app/socket.io/?EIO=4&transport=websocket&sid=8hBsGeYA_IrY5q7LAAASNS_ERROR_WEBSOCKET_CONNECTION_REFUSED

Firefox can’t establish a connection to the server at wss://compiler-production-7afb.up.railway.app/socket.io/?EIO=4&transport=websocket&sid=8hBsGeYA_IrY5q7LAAAS.

Note there is no error showing in the backend service logs in this case.

Awaiting User Response

1 Replies

4 months ago

Hello,

You are likely storing some state in memory, this is an issue since we don't support sticky sessions, you need to store state globally in Redis so that it doesn't matter what replica answers' the request since all replicas will have access to the global state in Redis.

Unfortunately we cannot help you implement this or offer any project help since we can only assist with the Railway platform or product, the best we can do here would offer the advice above, you will in turn need to re-architecture your app accordingly.

Best,
Brody


Status changed to Awaiting User Response railway[bot] 4 months ago