socketio / socket.io-postgres-adapter

The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
https://socket.io
MIT License
24 stars 8 forks source link

await socket.join is not waiting for other instances to have updated state #12

Open NykolaySavin opened 1 year ago

NykolaySavin commented 1 year ago

Hello, I am using Socket io v4 with Postgres adapter. All events are broadcasted and everything is working good except this case. I have function that is joining room and exactly after that sending message.

await socket.join("room-id");
this.server.in('room-id').emit(event, payload);

I was actually trying to understand this adapter code and have feeling that await is not waiting for other instances of server to join room - that's why event is not broadcasted to all instances

darrachequesne commented 1 year ago

Hi! socket.join() only updates the local state, the other instances are not notified.

NykolaySavin commented 1 year ago

Hello, thank you for response. Then how can I notify other instances about socket joining some room?

NykolaySavin commented 1 year ago

@darrachequesne actually I was doing await socket.join("room-id"); where socket instanceof RemoteSocket and remote instance were notified about it, but problem is that await is not waiting

darrachequesne commented 1 year ago

Yes you are right, with a RemoteSocket the socketsJoin() method does not currently wait for the acknowledgement of the other nodes of the cluster. That being said, the other nodes should receive the JOIN command first, and then the BROADCAST command, so it should work I guess.