-
Notifications
You must be signed in to change notification settings - Fork 487
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
Comments
I might have pinned the issue down to be in |
You are absolutely right, the This should be fixed by socketio/socket.io@30430f0. Thanks a lot for the detailed report 👍 |
This was fixed in |
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 usingserver.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
The text was updated successfully, but these errors were encountered: