Skip to content

Redis subscription is not unsubscribed #946

@tomi-bigpi

Description

@tomi-bigpi

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:

  1. Use extension-redis in any project.
  2. Connect a client to the server.
  3. Use redis-cli and PUBSUB NUMSUB "documentName" to check the number of subscriptions.
  4. Disconnect the client.
  5. 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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions