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

Issues with fetchSockets() #454

Closed
schw4rzlicht opened this issue May 2, 2022 · 3 comments
Closed

Issues with fetchSockets() #454

schw4rzlicht opened this issue May 2, 2022 · 3 comments

Comments

@schw4rzlicht
Copy link

schw4rzlicht commented May 2, 2022

Hey there,

we are currently facing multiple issues with fetchSockets() in a Nest.js backend using @socket.io/redis-adapter.

First, we tried to use server.to("room").fetchSockets().then((socket) => ...) to emit to all sockets across all containers (with the help of Redis adapter) as we needed to process every socket individually (emitting user-specific data to each socket).

We are running on AWS ElastiCache and noticed that when using the aforementioned mechanism, only sockets of the local container are returned, thus nobody who is connected to other containers will receive the event. This works fine locally across multiple containers though.

We came up with a work around that uses server.local.to("room").fetchSockets() and then emits a server-side event in order to do the same on all other containers. We also found this to scale better as we're distributing business logic that runs on those sockets to all containers. So while we were pretty happy with the work around, it doesn't work unfortunately. And this time it is locally reproducible. For some reason, server.local.to("room").fetchSockets() does (inconsistently) return all sockets across all containers, thus emitting the event to every socket multiple times.

When subscribing to Redis Pub/Sub using redis-cli it also looks like every container is requesting all sockets from all containers, although using server.local.....

We are pretty lost currently when it comes to ideas where to debug and how to fix this issue, therefore we're asking here. We also asked on the Nest.js discord, although we believe this is either a problem with the Redis adapter or with socket.io itself (thus my next question: does this issue belong in this repository or should we open another issue in the socket.io repo?).

Thanks a lot for your help!

Relevant versions in use

  • @nestjs/platform-socket.io@8.4.4
  • socket.io@4.4.1
  • @socket.io/redis-adapter@7.1.0

Reproduction code

/cc @fan711

@schw4rzlicht
Copy link
Author

I might have pinned the issue down to be in BroadcastOperator thus not being an issue of the Redis adapter. Opened an issue in the socket.io repository: socketio/socket.io#4359

@darrachequesne
Copy link
Member

You are absolutely right, the flags was not forwarded to the adapter.

This should be fixed by socketio/socket.io@30430f0.

Thanks a lot for the detailed report 👍

@darrachequesne
Copy link
Member

This was fixed in socket.io@4.5.1: https://github.com/socketio/socket.io/releases/tag/4.5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants