Sometimes latest changes get reverted (during sync?)

OS Family: Linux
System: KDE Neon (Ubuntu 18.04 LTS 64-bit)
Joplin: 1.0.193 appimage

Hello,

I’ve noticed a pretty annoying issue that I tried to triage when on Joplin 1.0.179. It seemingly vanished in the meantime, I also partially attributed this to Issues I had with the Nextcloud Desktop Client.

As it stands today, the Nextcloud Client is working really well, Joplin got updated and all seemed well. But a while ago today I noticed that the issue is still there.

When I write my notes, sometimes the note gets reverted to its previous state, I’m 95% certain that this happens during sync. That’s because I saw this once happen: I was writing, Joplin started to sync and my changes vanished. But an identical scenario happened many times and there was no data loss.

Right now I’m typing manually my notes that I’ve written on paper, so I have verbatim what was typed. I wanted to add some more text to a specific place and the last added piece was missing. I tried searching with CTRL+g for the word travel that was in the previous sentence. And no dice, the sentence is nowhere to be found. So either I’m using the wrong tool to search, or the sentence disappeared.

I tried to time something a while ago: to edit a note exactly when the sync is running, but I couldn’t recreate this situation. Maybe it gets triggered by something else and sync is simply happening nearby. I’m also not sure if there was any sync when I was typing today, I may have refocused to a different note or simply looked away.

I’ve secured the logs for today and here’s the timestamp of the note in question: 2020-02-29 12:56

There are no errors or warnings in the logs, but I can go through them again once I know what to look for.

So… how does exactly Joplin save and sync notes? Could there be an edge case where operations collide or race against each other in such a way that the note gets restored to a previous state?

Oh, I've found the new version of the note in the Conflicts folder... Timestamp 2020-03-13 16:23:

:thinking:

I've pasted the raw text to meld and sure enough: there are differences, but if the note was edited two weeks ago, then why have a conflict with itself?

I greped by the timestamp.

$ grep '16:23' revert-note-debug 

2020-03-13 16:23:00: "Scheduling sync operation..."
2020-03-13 16:23:05: "SearchEngine: Updating FTS table..."
2020-03-13 16:23:05: "Scheduling sync operation..."
2020-03-13 16:23:05: "SearchEngine: Updated FTS table in 166ms. Inserted: 1. Deleted: 0"
2020-03-13 16:23:09: "RevisionService::maintenance: Starting..."
2020-03-13 16:23:09: "RevisionService::maintenance: Service is enabled"
2020-03-13 16:23:09: "Scheduling sync operation..."
2020-03-13 16:23:09: "RevisionService::collectRevisions: Created revisions for 2 notes"
2020-03-13 16:23:09: "RevisionService::maintenance: Done in 348ms"
2020-03-13 16:23:10: "Scheduling sync operation..."
2020-03-13 16:23:19: "SearchEngine: Updating FTS table..."
2020-03-13 16:23:19: "SearchEngine: Updated FTS table in 171ms. Inserted: 1. Deleted: 0"
2020-03-13 16:23:40: "Preparing scheduled sync"
2020-03-13 16:23:40: "Starting scheduled sync"
2020-03-13 16:23:42: "DecryptionWorker: starting decryption..."
2020-03-13 16:23:42: "TaskQueue.stop: syncDownload: waiting for tasks to complete: 0"
2020-03-13 16:23:42: "TaskQueue.stop: syncDownload: Done, waited for 0"
2020-03-13 16:23:42: "Operations completed: "
2020-03-13 16:23:42: "noteConflict: 1"
2020-03-13 16:23:42: "createRemote: 2"
2020-03-13 16:23:43: "Total folders: 69"
2020-03-13 16:23:43: "Total notes: 462"
2020-03-13 16:23:43: "Total resources: 2091"
2020-03-13 16:23:43: "Scheduling sync operation..."
2020-03-13 16:23:43: "DecryptionWorker: completed decryption."
2020-03-13 16:23:51: "SearchEngine: Updating FTS table..."
2020-03-13 16:23:51: "SearchEngine: Updated FTS table in 175ms. Inserted: 1. Deleted: 0"

This is a longshot, but would this be of any use to you: https://github.com/laurent22/joplin/issues/808

I’ve read the issue and sadly, I don’t think this would be applicable. I’m using Nextcloud WebDAV only on Android. On PC and laptop I’m using the Nextcloud Sync Client.

Moreover, I see that once again my endpoints lost sync:

PC
Screenshot_20200313_211747
laptop
Screenshot_20200313_213116
I really don’t want to use the touch * workaround again.

What can be done to prevent this from happening? Is anyone else having similar issues? I wanted to start moving more and more data to Joplin and make it my one and only note taking program. But now I’m having second thoughts.

Does this mean you’re using Filesystem sync in Joplin on the Desktop clients? I’m asking because, despite not being to assist much further with this, that piece of information could be the key to finding out what’s actually happening here. Any extra information is always better than being stuck guessing what’s happening. Thanks

Also, are both desktops running the same OS as posted in the first post?

I haven't read your post in detail yet, but some comments about sync how sync works:

Sync uses files and relies on accurate file timestamps, so ensuring the clocks on the machines at either end is important. If the machines don't have the same time of day, then sync will be given incorrect information to work with, and won't do what it is meant to do.

This can also be affected by the way different machines and filesystems handle file timestamps Eg

Could any of this explain what you're seeing?

This is particularly true when dual booting Linux and Windows on same machine. I keep forgetting about that, although, this situation doesn’t seem to be exactly that, but i digress.

I think you can edit the Windows registry to make Windows use UTC time, and so solve that problem.

1 Like

Hello,

yes, I forgot to mention I use the Filesystem sync on both ends. The ~/Nextcloud/Joplin folder is being synced automatically.

Both the laptop and desktop run the same config:

OS Family: Linux
System: KDE Neon (Ubuntu 18.04 LTS 64-bit)
Joplin: 1.0.193 appimage

Could things like not booting one of the computers for a few days or one of them being offline for some time affect the sync? If timestamps are in use, then I should be able to work for an extended time on an offline system and have no issues once it gets plugged again (I had a network outage for a few days and relied on tethering at times).

What’s the role of Joplin/.sync/version.txt? It gets modified every-time I sync. Is it to keep track of the last sync time?

@mic704b I don’t dual boot, I don’t run Joplin on Windows.

Should I start a separate thread about general sync issues, since the reverting of the notes may be a separate issue.

EDIT: And yes, the dates and times are in sync.

I’m not fully sure with the technical side of things, and would rather wait for Mic to get back to you on this one. I’m the one that asked about dual booting to make sure I understood what he was referring to since dual booting frequently causes timestamp issues.

It shouldn't. As long as the computers clock isn't drifting too much.

Correct.

The fact your updated note was found in the Conflict folder means it is most likely due to sync. If the note was edited on both this and the other computer since the last sync, then the note on this computer will be moved to Conflict, and the note from the other will replace it. Which seems pretty much like what you're seeing.

The first thing I suspect is the sync file timestamps.

I should say I have no experience with syncing with Nextcloud, so I don't know specific issues related to that.

I have an idea.

Previously, Joplin was slow to sync when using the Nextcloud back-end, but this has been resolved. What if I switch from the File-system back-end on both PC and laptop to the Nextcloud back-end?

That way I’d bypass the Nextcloud Desktop Client (it would still download changes, but Joplin would not care anymore). Since it would be only Joplin doing the modifications in this folder (~/Nextcloud/Joplin) this would allow me to troubleshoot further. Or maybe I should disable Nextcloud sync completely for Joplin’s folder, just to be safe?

I suspect, that before I continue, I should at the very least resolve the conflicts to make sure nothing gets mangled. A backup would be advisable.

ALSO: should I do touch ~/Nextcloud/Joplin/* before I switch to the Nextcloud back-end? I don’t want to accidentally “improve things too much” to the point where the whole experiment becomes no longer representative.

@mic704b - should I go forward with what I proposed above?

Unfortunately I have no experience with sync via NextCloud so I am not the best person to advise you and don’t know how it should be setup. I hope someone else will chime in.

However whatever you do, first make sure you have good backups to insure you against data loss. It’s a good idea anyway, but even more important here when playing with sync.

Is it possible that NextCloud is updating the file timestamps in the sync target, even when they are not changing? If this happens then your client will think they are newer than when last synced, and might do what you saw.

First I would look at the file timestamps, and see if they look correct. Perhaps see if you can replicate the problem with one note (and so one sync file), and follow it all the way through your setup, checking the timestamp along the way, if possible.

Apart from that, I encourage you to experiment. BUT BACKUP FIRST!

Backup ensures you don’t lose your data. It also can allow you to recreate everything so you can try different experiments from the same starting point.

Let me correct something I wrote earlier.

This is inaccurate, as the note won't be moved, just the content. In the case discussed, sync makes a new note in the conflict folder, with the content of the local note. The original note is then updated, depending on the type of conflict.

Alright. I’ll try reserving some time over the weekend and see what I can find.

I'm still not done with the testing. I actually had a setback: I borked the data and had to restore from backup (always back up, kids!). So the results won't be coming in soon.

But one question popped into my head in the meantime: is it normal, that after switching sync methods Joplin wants to sync everything from the ground up?
:thinking:
I went from file-system sync pointing to a folder managed by Nextcloud Desktop Sync to the Nextcloud back-end in Joplin and Joplin wanted to sync all. I allowed it but it was extremely slow (about 70 notes in 15 minutes) so I aborted.

Shouldn't Joplin just "get in touch" with the backend and sync only what's missing? If there is anything to sync at all?
:thinking:

1 Like

Yet another question popped up:

if I'm using NextCloud, does the server need to have a "joplin application" installed? Because I saw an error saying, that the Joplin application is not installed. In the logs I see this from that time:

 41 2020-03-28 21:37:13: "Total resources: 3007"
 40 2020-03-28 21:39:53: "Could not setup sync target:", "Error: Unsupported WebDAV URL format: https://REDACTED.TLD/remote.php/dav/files/REDACTED@REDACTED.TLD/Joplin
 39 Error: Unsupported WebDAV URL format: https://REDACTED.TLD/remote.php/dav/files/REDACTED@REDACTED.TLD/Joplin
 38     at Function.baseUrlFromNextcloudWebDavUrl (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:60:19)
 37     at Object.baseUrl (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/SyncTargetNextcloud.js:59:35)
 36     at JoplinServerApi.baseUrl (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:53:43)
 35     at JoplinServerApi.<anonymous> (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:117:33)
 34     at Generator.next (<anonymous>)
 33     at /tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:8:71
 32     at new Promise (<anonymous>)
 31     at __awaiter (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:4:12)
 30     at JoplinServerApi.exec (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:99:16)
 29     at JoplinServerApi.<anonymous> (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:75:25)"
 28 2020-03-28 21:39:59: "Could not setup sync target:", "Error: Unsupported WebDAV URL format: https://REDACTED.TLD/remote.php/dav/files/REDACTED@REDACTED.TLD/Joplin
 27 Error: Unsupported WebDAV URL format: https://REDACTED.TLD/remote.php/dav/files/REDACTED@REDACTED.TLD/Joplin
 26     at Function.baseUrlFromNextcloudWebDavUrl (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:60:19)
 25     at Object.baseUrl (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/SyncTargetNextcloud.js:59:35)
 24     at JoplinServerApi.baseUrl (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:53:43)
 23     at JoplinServerApi.<anonymous> (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:117:33)
 22     at Generator.next (<anonymous>)
 21     at /tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:8:71
 20     at new Promise (<anonymous>)
 19     at __awaiter (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:4:12)
 18     at JoplinServerApi.exec (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:99:16)
 17     at JoplinServerApi.<anonymous> (/tmp/.mount_JoplingmrqfN/resources/app.asar/lib/JoplinServerApi.js:75:25)"

So... does Nextcloud require some special configuration before I point to it with the Nextcloud sync backend in Joplin? :thinking: And otherwise I have to use WebDav? :thinking:

EDIT: I just got an error and I see lots of locking errors! A sample:

2020-03-28 22:08:27: "Error: PUT 182720c314184719a00c952fcbb6befe.md: "Joplin/182720c314184719a00c952fcbb6befe.md" is locked (Exception OCA\DAV\Connector\Sabre\Exception\FileLocked) (423): <?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>OCA\DAV\Connector\Sabre\Exception\FileLocked</s:exception>
  <s:message>"Joplin/182720c314184719a00c952fcbb6befe.md" is locked</s:message>
</d:error>

Does this look like a potential suspect for slow sync @laurent ?

The locking issue is a bug in Nextcloud. There are many threads about it in their forum (and a few here too).

Hello,

I'm seeing also errors like this:

2020-03-28 22:21:27: "Res 22:18:59: <?xml version="1.0" encoding="utf-8"?>
<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
  <s:exception>Sabre\DAV\Exception\MethodNotAllowed</s:exception>
  <s:message>The resource you tried to create already exists</s:message>
</d:error>

but after reading this

I assume that this is not an issue with Joplin.

I created a thread on the NC forums:

with the hope, that someone will pick this up, but so far only one response.

This is really frustrating. I was so happy, that I'd be able to migrate all of my notes, but now everything is on halt while "a breakthrough happens".

:frowning:

Any ideas what can we do with this to find more information?

EDIT: Maybe it's the preview generator causing trouble?