Empty session content with single step in the database and file content preserved
Describe the bug We observed on two different instances that the content of a file turned empty.
Investigating it in more detail we found the following:
- There was no
.vuefile in the documents app folder. - there was only one step entry in the database
- there were two sessions in the database - most likely because we were looking at the document in two tabs.
To Reproduce We are still to find reliable steps to reproduce the behavior. In one case this is what triggered it:
- Open new page in collectives
- Edit it for a while
- Close the laptop lid
- Reopen after approx 1 hour
- reopen the document and see it empty.
- Markdown file content is preserved.
Expected behavior The file content in the editing session should still exist.
Screenshots Imagine an empty editor view here. :wink:
Server details:
- Nextcloud version: 27.1.15
- PHP Version: 8.2
- Database: MariaDB
As mentioned in the call we should check if this is reproducible somehow by manually resetting the document state and steps.
Another thing to check is if the cleanup of steps/document state is save-guarded to also cleanup sessions so at least a new session would be created then on reconnect?
I just tried the following:
- edit a document
- disconnect (via network throttling)
- type some more before reconnect button shows
- cleanup document with
./occ text:reset -f 1390 - turn network on again
Text fails to reconnect automatically as the session is gone After clicking reconnect the doc reopens with a clean state without the unsend steps.
So that seemed okay - not sure if it will always work that way though.
I think we will need to separate the sync service session and the yjs session conceptually and in practice.
Sync service session
Connects all users that are editing the document at the same time.
- ephemeral
- cleaned up when no users are active anymore
- created as needed
- backend for the SyncServiceProvider in yjs
Yjs session
- long running
- contains the editing history and the yjs document state at the time of saving
- used to recover and resume the editing session
- might contain info for user colors in the long run
Even if we keep the yjs doc around there's still a way to be missing steps from one peer:
- one client keeps edits, closes lid
- some steps send but not saved yet
- session ends
- session is cleaned up
- document state does not have latest steps from that client yet even though client already send them.
- lid opened again
- new session created from existing yjs session
- client proceeds
- other clients that connect will miss the steps that the client send between the last save and closing the lid
Possible solution
When reconnecting:
- apply document state from yjs file again to make sure we are in sync with edits that happened in between
- compute diff between local yjs and document state on server
- send diff as update if it exists.
We could even compute this regularly to make sure everyone stays in sync.
Given that we guess this is fixed with Nextcloud 27.1.6 and 28.0.2, let's close the issue for now. We can reopen it later on if there's new reports about this missbehaviour.