Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
NykolaySavin opened this issue Mar 29, 2023 · 4 comments
Labels
question Further information is requested

Comments

@NykolaySavin
Copy link

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
Copy link
Member

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

@NykolaySavin
Copy link
Author

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

@NykolaySavin
Copy link
Author

@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
Copy link
Member

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.

@darrachequesne darrachequesne added the question Further information is requested label Apr 3, 2023
darrachequesne added a commit to socketio/socket.io-adapter that referenced this issue Feb 22, 2024
Before this change, the broadcast() method would send the BROADCAST
command and then apply it locally (which is required to retrieve the
offset of the message, when connection state recovery is enabled),
while the other commands like disconnectSockets() would first apply it
locally and then send the command to the other nodes.

So, for example:

```js
io.emit("bye");
io.disconnectSockets();
```

In that case, the clients connected to the io instance would not receive
the "bye" event, while the clients connected to the other server
instances would receive it before being disconnected.

Related:

- socketio/socket.io-redis-streams-adapter#13
- socketio/socket.io-postgres-adapter#12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants