You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My project utilizes the ShardedRedisAdapter and Redis v7 to sync state across server instances. I am using the default "dynamic" subscription mode which creates a new channel subscription for each public room.
When a room is created, the new channel subscription is created and the adapter adds a listener to the client's smessageBuffer EventEmitter (by way of SSUBSCRIBE in /lib/util.ts). However, this event listener is not removed when the room is deleted, and consequently I'm encountering a MaxListenersExceededWarning when creating more than 8 rooms regardless of whether the rooms still exist.
I should increase the client's max listener threshold since it will not be uncommon to have >8 rooms at any given time, but it also looks like SUNSUBSCRIBE should be updated to remove the smessageBuffer listener. I'm happy to raise a PR to address this, but wanted to make sure I'm not missing something! Thanks in advance!
The text was updated successfully, but these errors were encountered:
This pull request introduces a change to the sharded adapter's `SSUBSCRIBE` logic: Previously, for each dynamic channel/room, a unique listener was added to the client's `smessageBuffer`. This approach led to a large number of listeners (resulting in `MaxListenersExceededWarning`), especially in scenarios with many dynamic channels. Further, listeners were not being removed when unsubscribing, leading to a memory leak.
The new implementation replaces the multiple listeners with a single `smessageBuffer` listener. This listener is registered once and handles all dynamic channels by maintaining specific channel handlers in a `Map`. Listeners are added to this `Map` in `SSUBSCRIBE` and removed from the `Map` in `SUNSUBSCRIBE`.
Related: #528
My project utilizes the
ShardedRedisAdapter
and Redis v7 to sync state across server instances. I am using the default "dynamic" subscription mode which creates a new channel subscription for each public room.When a room is created, the new channel subscription is created and the adapter adds a listener to the client's
smessageBuffer
EventEmitter (by way ofSSUBSCRIBE
in /lib/util.ts). However, this event listener is not removed when the room is deleted, and consequently I'm encountering aMaxListenersExceededWarning
when creating more than 8 rooms regardless of whether the rooms still exist.I should increase the client's max listener threshold since it will not be uncommon to have >8 rooms at any given time, but it also looks like
SUNSUBSCRIBE
should be updated to remove thesmessageBuffer
listener. I'm happy to raise a PR to address this, but wanted to make sure I'm not missing something! Thanks in advance!The text was updated successfully, but these errors were encountered: