Skip to content

emit before disconnectSockets #13

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

Closed
SupertigerDev opened this issue Feb 20, 2024 · 3 comments
Closed

emit before disconnectSockets #13

SupertigerDev opened this issue Feb 20, 2024 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@SupertigerDev
Copy link

SupertigerDev commented Feb 20, 2024

I have code where I emit before disconnecting the user. However, the User is disconnected before the event is emitted. Is there some kind of await thing i could use for emit?

io.in(opts.to).emit(AUTHENTICATE_ERROR, {
   message: opts.message,
   data: opts.data,
});
io.in(opts.to).disconnectSockets(true);

Notes:
• When removing disconnectSockets, the emit function works.
• When removing this streams adapter, the emit + disconnectSockets both work perfectly.

@darrachequesne
Copy link
Member

I could indeed reproduce the issue, I'm digging into this...

@darrachequesne darrachequesne added the bug Something isn't working label Feb 21, 2024
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
@darrachequesne
Copy link
Member

This should be fixed by socketio/socket.io-adapter@a13f35f, included in socket.io-adapter@2.5.4 (and thus @socket.io/redis-streams-adapter@0.2.0).

Could you please check?

@SupertigerDev
Copy link
Author

Seems to be fixed, thanks ❤️

@darrachequesne darrachequesne added this to the 0.2.0 milestone Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants