-
-
Notifications
You must be signed in to change notification settings - Fork 165
Description
Description
During a provider client reconnect, we're observing that before/afterUnloadDocument
hooks are being called twice, after which the Yjs document is destroyed and updates from the client are silently lost.
Logging from the reconnect showing before/afterUnloadDocument
being called immediately after the document is loaded:

Later logs where Sync/Update
messages are received but there are no corresponding out
messages to the client nor Document X changed
log messages:

Steps to reproduce the bug
I haven't been able to reproduce it directly, but I'm pretty sure the bug is caused by the debounced logic in extension-redis:
- Client disconnects
onDisconnect
hooks are called (and awaited, as of Fixes a bug in extension-redis that leads to broken sync when clients… #587)
a. The Redis hook resolves immediately, even though it starts a timeout to unsubonClose
is called, document is unloaded because there are no active connections- Client reconnects, calling
setUpNewConnection
->createDocument
- Document is not loaded, so
loadDocument
is called
a. Document is added to instance withthis.documents.set(documentName, document)
b.onLoadDocument
hooks are called - At some point during the async
onLoadDocument
hooks, the RedisonDisconnect
timeout triggers
a. It callsthis.instance.documents.get(documentName)
, which returns the new document being loaded
b. There are no active connections for the document, so it is unloaded (connectionCount: 0
in screenshots above) loadDocument
->createDocument
finish runningsetUpNewConnection
callscreateConnection
->new Connection
->this.document.addConnection(this)
- Updates come in from client (
connectionCount: 1
in screenshots above) however it's already too late
You can reproduce the broken state by adding an extension:
afterLoadDocument: async (data) => {
data.instance.unloadDocument(data.document);
},
Expected behavior
extension-redis does not call unloadDocument
for the newly loaded document. #831 made it so the extension used the latest document from the Hocuspocus instance, rather than the one passed into the hook, which strikes me as odd.
Environment?
- Hocuspocus version: 2.15.3