-
-
Notifications
You must be signed in to change notification settings - Fork 165
Description
Description
The Redis subscription unsubscribe code is behind a setTimeout
which checks if the document
instance is still available on the parent instance
, which for us is never since the document is disposed by the time the setTimeout
code is called.
This will cause unnecessary resource usage, potential memory leaks, and prevents leveraging PUBSUB NUMSUB
to check across multiple Hocuspocus instances whether all clients have disconnected (not just the current server, though that won't be reliable in a Redis cluster which will only return the number of subscribers per Redis node).
Steps to reproduce the bug
Steps to reproduce the behavior:
- Use extension-redis in any project.
- Connect a client to the server.
- Use redis-cli and
PUBSUB NUMSUB "documentName"
to check the number of subscriptions. - Disconnect the client.
- Check the number of Redis subscriptions - the subscription is still active.
I also verified with additional logging locally and the this.sub.unsubscribe
is never called due to the check for an existing document above this row.
Expected behavior
The extension should subscribe from Redis pubsub when no clients are connected.
Environment?
- operating system: macOs
- browser: Chrome
- mobile/desktop: Desktop
- Hocuspocus version:
"@hocuspocus/extension-redis": "2.15.2"
Additional context
The unloadDocument
is also suspect due to the delay caused by setTimeout
for the disconnect and the potential for additional asynchronous connections to happen during the delay.
I've created a PR here: #945