socket.io-redis-adapter icon indicating copy to clipboard operation
socket.io-redis-adapter copied to clipboard

Question: remote socket + event emitter ?

Open fxi opened this issue 3 years ago • 2 comments

Hello,

Would it be possible to have/recreate a full Socket from fetchSockets instead of the partial RemoteSocket ? Currently, if the socket is not local, it lacks some EventEmitter methods and it's is blocking for a specific case on a cluster.

Maybe I missed something :/

Thanks

fxi avatar Jun 23 '22 13:06 fxi

@fxi you mean, having the on() method and such? In that case, that's not currently possible.

What you can do is use the serverSideEmit() method: https://socket.io/docs/v4/server-instance/#serversideemit

darrachequesne avatar Jun 26 '22 07:06 darrachequesne

Yep, thanks.

That's exactly that : I was trying to catch an event from a non-local socket. It was not clear for me that on/once were not available on remote socket: during testing, I was on a single node. On multiple nodes, local sockets are complete but remote sockets are partial.

I was mixing HTTP request to launch a process and websocket to feedback progress and listen for data from the browser in an optional async task.

I started converting everything using websocket/socket.io, including authentication. That's a consequent change, but it will simplify the whole thing.

I also got a sticky session issue in the first place: our proxy/load-balancer only allows cookie based stickiness, and it does not work when cookies are not allowed. ws connection were kept on the same server as the ws connection, but subsequent request were done on any node. It's basic, but after reading the doc, I was convinced that fetchSockets and redis-adapter were the solution.

Anyway, thanks again !

fxi avatar Jun 26 '22 19:06 fxi