Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend does not return current content of file #2729

Open
susnux opened this issue Jul 19, 2022 · 6 comments
Open

Backend does not return current content of file #2729

susnux opened this issue Jul 19, 2022 · 6 comments
Labels
bug Something isn't working feature: sync high

Comments

@susnux
Copy link
Contributor

susnux commented Jul 19, 2022

Describe the bug
Discovered while testing using the (cypress) docker image:

I created a file and wrote some text into it, (quickly) closed it and tried to reopen it again.
When trying to reopen it the text app does not load it but throw an error:

Uncaught
Object { message: "Failed to serialize document to plain text" }
EditorFactory.js:147:8

{
  "message": "Failed to serialize document to plain text"
}

I have added some debug outputs to the EditorFactory and the SyncService and discovered the file is never loaded, as the call to _fetchDocument in the open function of the SyncService always just returns an empty string.

I can download the file using the files app and there the content is correct.
I tried to rename the file / logout / reload / try an other browser and even to use another user and open that file but that does not work either (same error).

To Reproduce
I could not reproduce it with an other file...
But I have attached a backup of the data directory (including the sqlite database) so you should be able to reproduce by creating the docker image and replace the data directory with the attached one. backup.zip

Client details:

  • OS: Linux
  • Browser: Firefox 102 and Chromium 103
  • Version: master
@susnux susnux added the bug Something isn't working label Jul 19, 2022
@juliusknorr
Copy link
Member

Thanks for the dump, do you still know which file was affected?

@susnux
Copy link
Contributor Author

susnux commented Jul 19, 2022

Thanks for the dump, do you still know which file was affected?

it is cccc.txt

@susnux
Copy link
Contributor Author

susnux commented Jul 19, 2022

I noticed that this is a combination of two different bugs, the first one is the reported one, the second is only the exception thrown and (by luck) allowed me to discover the first one:

  1. The text backend does not respond with the correct file content, it returns an empty string instead of the actual content
  2. The plaintext serializer has a bug, as it checks if the first element is a code_block but tiptap uses the type name codeBlock so this is always false.

I fixed locally the second bug, but now the file is opened as "empty" and instantly saved back so the file content is overwritten and the backend responses the "correct" content again.

@juliusknorr
Copy link
Member

The backend would return a copy of the file at the point when it was opened, in case there are still unsaved steps applied on top. This base file version is stored in appdata_*/text/. So maybe with the broken plaintext serializer it ended up not saving the file but also wasn't able to restore the state on reopening from the steps.

@susnux
Copy link
Contributor Author

susnux commented Jul 20, 2022

Hm but the file was saved, as the files app can download the files containing the content.
As it was created empty -> pasted content -> auto-saved -> closed then on reopening it failed.

Is it possible that the backend saved the file but not updated its state of the file?
As I was not able to reproduce it, it might just been some kind of race condition

@juliusknorr
Copy link
Member

Nothing I could think of without throwing an error that should have landed in the logs:

try {
$this->lockManager->runInScope(new LockContext(
$file,
ILock::TYPE_APP,
Application::APP_NAME
), function () use ($file, $autoaveDocument) {
$file->putContent($autoaveDocument);
});
} catch (LockedException $e) {
// Ignore lock since it might occur when multiple people save at the same time
return $document;
}
$document->setLastSavedVersion($document->getCurrentVersion());
$document->setLastSavedVersionTime(time());
$document->setLastSavedVersionEtag($file->getEtag());
$this->documentMapper->update($document);
$this->cache->remove('document-save-lock-' . $documentId);
return $document;
for reference on where the save is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature: sync high
Projects
Status: 📄 To do (~10 entries)
Development

No branches or pull requests

4 participants