fix: Memory leak in Direct Connection#895
Merged
janthurau merged 3 commits intoueberdosis:mainfrom Feb 20, 2025
Merged
Conversation
Contributor
Author
|
@janthurau any update on this one? |
Contributor
Author
|
@janthurau bumping this again since this is causing problems |
janthurau
reviewed
Feb 19, 2025
8b75816 to
c786618
Compare
janthurau
approved these changes
Feb 20, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
onStoreDocumentreturns a rejected promise due to failing to acquire a lock.thento continue to callstoreDocumentHooks, preventingafterStoreDocument,unloadDocumentandafterUnloadDocumentto be called. This is how the memory leak occursafterStoreDocumentis never triggered. That's fine, we don't need to release a lock that we never acquired.onDisconnecthooks when calling .disconnect() on the direct connection, the redis extensionsonDisconnectlogic isn't triggered either. The fix to unload the document associated with the direct connection here https://github.com/ueberdosis/hocuspocus/pull/831/files is never reached.I don't think we should unload the document if the store document hook returns a rejected promise. Take for example, an autosave that is implemented through a debounced
onStoreDocument. We wouldn't want the server to suddenly unload the active document if for some reason that autosave failed.However, if we confirm that the direct connection is the ONLY connection to that document, we can trigger the 'onDisconnect' hook and can call
unloadDocumentfor that document when we call .disconnect() on the direct connection. This should ensure the document is unloaded, consequently preventing unused loaded documents from accumulating on the server.