Replies: 1 comment
-
I don't understand this. If each worker connects to Redis using the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am working on a project that uses Socket.IO to send messages to multiple clients. The server is launched using uWSGI with the --lazy-apps flag and multiple workers. To ensure that messages reach all clients, regardless of the worker they are connected to, I am using Redis Pub/Sub.
The issue arises when the Socket.IO service is launched, as each worker runs Redis Pub/Sub independently, which causes message duplication. For example, if there are 4 workers, each one independently subscribes to the same Redis channel. As a result, when a message is sent via Socket.IO, each client receives the message 4 times—once per worker. The number of duplicate messages corresponds to the number of workers.
The flow is as follows: A method creates the message, which is passed to another method that publishes it to Redis Pub/Sub. A message listener subscribes to the Redis channel and emits the message. Each worker initializes its own instance of the listener, meaning when a message is sent via Socket.IO, it triggers the listener in every worker and causes the message to be sent multiple times.
Currently, I am using client_manager set to RedisManager when initializing the Socket.IO server. While this setup works for message distribution, I want to avoid duplication and share the Redis Pub/Sub instance across all workers to ensure messages are only sent once to each client.
As a temporary workaround, I have forced the message listener to initialize only for worker 1, but this introduces a risk. If worker 1 fails, the Pub/Sub mechanism will also fail. I need a more reliable solution to ensure message delivery without duplication and with resilience to worker failures. How can I achieve this?
Beta Was this translation helpful? Give feedback.
All reactions