pbek / QOwnNotes

QOwnNotes is a plain-text file notepad and todo-list manager with Markdown support and Nextcloud / ownCloud integration.
https://www.qownnotes.org/
GNU General Public License v2.0
4.64k stars 411 forks source link

Sync race between qown <-> nextcloud client #1041

Closed cls-nebadje closed 4 years ago

cls-nebadje commented 6 years ago

When editing notes within QOwnNotes and the Nextcloud client syncs in the meanwhile I get bugged all the time with the "The current note was modified outside of this application" warning.

This makes editing virtually impossible. And I won't check "Ignore all external modifications in the future" because this increases the risk to accidentally overwrite external changes.

It seems to me that QOwnNotes doesn't compute the differences between the version on the disk and the edited version correctly (see screenshot). The Nextcloud client probably touches the file for no obvious reason (perhaps because QOwnNotes modifies something over the API connection) and QOwnNotes gets the inotify message...

I currently have to disable the Nextcloud client sync temporarily to avoid this pretty annoying issue.

I'm using QOwnNotes - version 18.10.0 - Launchpad PPA - build 481 on Linux 4.15.0-36-generic #39~16.04.1-Ubuntu SMP Tue Sep 25 08:59:23 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

annoying conflict

pbek commented 6 years ago

I never had that issue on Ubuntu... Do you maybe have a 2nd instance of QOwnNotes open by accident? Something else must be writing to the note file if you are getting this message.

cls-nebadje commented 6 years ago

Nope, no second instance here:

dev@hell:~$ ps -e | grep QOwn
 3244 ?        00:02:11 QOwnNotes

I researched this issue before posting - it seems that there were others which had a similar issue previously. Issue #171 for instance works around the same problem by providing a feature to silence this warning.

I'm currently monitoring the note accesses using

while true; do inotifywait -e modify -e attrib -e access <path/to/notes/*.md>; echo $(($(date +%s%N)/1000000)); done

which isn't the best way but a first attempt to find out if there are multiple write accesses. But of course Murphy's one of my best friends and the problem currently doesn't show up ...

cls-nebadje commented 6 years ago

Ok, I can reproduce it by editing continuously with little pauses to trigger QOwnNotes' auto-saving. But the above monitoring doesn't reveal anything suspicious - just a single write access:

Setting up watches.
Watches established.
Notes/Test.md ACCESS 
1538926938803
Setting up watches.
Watches established.
Notes/Test.md MODIFY 
1538926939337
Setting up watches.
Watches established.
Notes/Test.md ACCESS 
1538926939468
Setting up watches.
Watches established.
Notes/Test.md ACCESS 
1538926941399
Setting up watches.
Watches established.
Notes/Test.md ACCESS 
1538926941953
Setting up watches.
Watches established.
[...]

Perhaps my monitoring method is buggy or there's a race condition within QOwnNotes -- e.g. the inotify handler runs in a different thread than the file saving or comparing.

Another detail: The warning dialog is closed and re-spawned by QOwnNotes within milliseconds multiple times (which is even more annoying when it pops up on a different workspace) - but I suspect that this symptom is somehow related to this issue.

cls-nebadje commented 6 years ago

Yeah, it looks like this could be a race condition within QOwnNotes: when comparing the file on the disk and the file in the editor, the disk file content lags the editor content.

And: currently I can trigger this issue only when enabling the Nextcloud client sync. I try to trigger it differently to get more insight what happens here. I suspect some race condition between the editor disk writing and the inotify callback or some other problematic implementation detail.

cls-nebadje commented 6 years ago

I can trigger this issue easily with disabled Nextcloud client by changing the time stamp of the file continuously without modifying the contents of the file (Note that changing the timestamp generates an ATTRIB and not a MODIFY event.):

while true; do touch Notes/Test.md; sleep .1; done

This leads to the assumption that the Nextcloud client is somehow involved (even if I'm currently not able to detect it) and QOwnNotes is not prepared for such a situation.

In other words: if QOwnNotes' inotify callback is triggered for whatever reason but the file hasn't changed things get messy.

I already took a glimpse at mainwindow.cpp but I need more time to get a decent overview of the interaction of the different callbacks (MainWindow::notesWereModified et al).

cls-nebadje commented 6 years ago

Ok, I'm currently building the thing... ;)

Here the instructions to set the stuff up on Ubuntu 16.04 LTS, PPA only:

git clone https://github.com/pbek/QOwnNotes.git -b master
cd QOwnNotes
git submodule update --init

# install tools and dependencies
sudo apt install qtcreator libqt5svg5-dev libqt5xmlpatterns5-dev qtdeclarative5-dev

# necessary on some systems if the following error occurs
# qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory
# https://askubuntu.com/questions/938422/qmake-is-not-recognized
sudo update-alternatives --install /usr/bin/qmake qmake /usr/lib/x86_64-linux-gnu/qt5/bin/qmake 100
sudo update-alternatives --config qmake

cd src
# configure for release build:
qmake
# configure for debug build:
# qmake CONFIG+=debug
make -j `nproc`

You can edit it into your build instructions.

cls-nebadje commented 6 years ago

More than 10k lines of code in one file - are you sure? Even my eclipse indexer gives up :)

pbek commented 6 years ago

Here the instructions to set the stuff up on Ubuntu 16.04 LTS, PPA only:

You don't need qtcreator for just building QOwnNotes, just Qt 5.

In other words: if QOwnNotes' inotify callback is triggered for whatever reason but the file hasn't changed things get messy.

I can't do much about that.

Yeah, it looks like this could be a race condition within QOwnNotes: when comparing the file on the disk and the file in the editor, the disk file content lags the editor content.

If an inotify event files for the current note we check in MainWindow::notesWereModified if the content of the current note on disk is different from the un-stored (but possibly modified in the editor) current note.

https://github.com/pbek/QOwnNotes/blob/d5b41a56ceac03cffe04302a9857e9b8e8368ee7/src/mainwindow.cpp#L2422

To tackle this problem we basically would need to store the current note twice. One for editing it and one unchanged for checking if anything was changed. Of course a checksum every time the notes will be stored to disk would also do the trick...

cls-nebadje commented 6 years ago

Exactly. You have to keep track of your edits - that's the problem here.

cls-nebadje commented 6 years ago

I just switched to https://github.com/laurent22/joplin

pbek commented 6 years ago

18.10.1

pbek commented 6 years ago

maybe the same issue like in #171

pbek commented 6 years ago

@cls-nebadje, @minthemiddle

There now is a new release, could you please test it and report if it works for you?

mid1221213 commented 5 years ago

Hello,

I'm using « QOwnNotes - version 19.5.1 - Snapcraft - build 535 » on Ubuntu 19.04 and I have exactly this issue. It seems that it is not actually fixed :-(

ruapho commented 4 years ago

Currently experiencing the same issue on QOwnNotes 19.12.9 - OBS - build 638. Syncing with nextcloud 2.6.1git.

pbek commented 4 years ago

Can you please be more specific.

ruapho commented 4 years ago
[Dez 17 14:57:03] [status]: Notizordner wurde extern verändert
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  0
[Dez 17 14:57:03] [debug]: storing note file:  "Note 2019-12-17T14.55.21.md"
[Dez 17 14:57:03] [debug]: stored note:  Note: <id>19 <name>"Note 2019-12-17T14.55.21" <fileName>"Note 2019-12-17T14.55.21.md" <noteSubFolderId>1 <relativePath>"technisches" <hasDirtyData>false
[Dez 17 14:57:03] [debug]: storeUpdatedNotesToDisk  - 'count':  1
[Dez 17 14:57:03] [status]: 1 Notiz auf Datenträger gespeichert
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  1
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  2
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  3
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  4
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  5
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  6
[Dez 17 14:57:03] [debug]: buildNotesIndex  - 'noteSubFolderId':  7
[Dez 17 14:57:03] [debug]: setupNoteFolderTables  - 'database version':  13
[Dez 17 14:57:03] [debug]: cloudConnection:  CloudConnection: <id>1 <name>"Standard" <serverUrl>"https://owncloud.ivanlukic.de" <username>"ilukic" <priority>1
[Dez 17 14:57:03] [debug]: fetchShares  - 'url':  QUrl("https://owncloud.ivanlukic.de/ocs/v2.php/apps/files_sharing/api/v1/shares")
[Dez 17 14:57:03] [debug]: notesWereModified:  "Note 2019-12-17T14.55.21.md"
[Dez 17 14:57:03] [debug]: Current note was modified externally!
[Dez 17 14:57:03] [status]: Aktuelle Notiz wurde extern verändert
[Dez 17 14:57:03] [debug]: openNoteDiffDialog  - 'changedNote':  Note: <id>19 <name>"Note 2019-12-17T14.55.21" <fileName>"Note 2019-12-17T14.55.21.md" <noteSubFolderId>1 <relativePath>"technisches" <hasDirtyData>true
[Dez 17 14:57:03] [debug]: Reply from  "/ocs/v2.php/apps/files_sharing/api/v1/shares"
[Dez 17 14:57:03] [debug]: Reply from share api
[Dez 17 14:57:03] [debug]: updateNoteShareStatusFromShare  - 'status':  "ok\n"
[Dez 17 14:57:04] [debug]: cloudConnection:  CloudConnection: <id>1 <name>"Standard" <serverUrl>"https://owncloud.ivanlukic.de" <username>"ilukic" <priority>1
[Dez 17 14:57:05] [debug]: notesDirectoryWasModified:  "/home/ilukic/Notes"
[Dez 17 14:57:05] [status]: Notizordner wurde extern verändert
[Dez 17 14:57:05] [debug]: buildNotesIndex  - 'noteSubFolderId':  0
[Dez 17 14:57:05] [debug]: storing note file:  "Note 2019-12-17T14.55.21.md"
[Dez 17 14:57:05] [debug]: stored note:  Note: <id>19 <name>"Note 2019-12-17T14.55.21" <fileName>"Note 2019-12-17T14.55.21.md" <noteSubFolderId>1 <relativePath>"technisches" <hasDirtyData>false
[Dez 17 14:57:05] [debug]: storeUpdatedNotesToDisk  - 'count':  1
[Dez 17 14:57:05] [status]: 1 Notiz auf Datenträger gespeichert
[Dez 17 14:57:06] [debug]: buildNotesIndex  - 'noteSubFolderId':  1
[Dez 17 14:57:06] [debug]: buildNotesIndex  - 'noteSubFolderId':  2
[Dez 17 14:57:06] [debug]: buildNotesIndex  - 'noteSubFolderId':  3
[Dez 17 14:57:06] [debug]: buildNotesIndex  - 'noteSubFolderId':  4
[Dez 17 14:57:06] [debug]: buildNotesIndex  - 'noteSubFolderId':  5
[Dez 17 14:57:06] [debug]: buildNotesIndex  - 'noteSubFolderId':  6
[Dez 17 14:57:06] [debug]: buildNotesIndex  - 'noteSubFolderId':  7
[Dez 17 14:57:06] [debug]: setupNoteFolderTables  - 'database version':  13
[Dez 17 14:57:06] [debug]: cloudConnection:  CloudConnection: <id>1 <name>"Standard" <serverUrl>"https://owncloud.ivanlukic.de" <username>"ilukic" <priority>1
[Dez 17 14:57:06] [debug]: fetchShares  - 'url':  QUrl("https://owncloud.ivanlukic.de/ocs/v2.php/apps/files_sharing/api/v1/shares")
[Dez 17 14:57:06] [debug]: notesWereModified:  "Note 2019-12-17T14.55.21.md"
[Dez 17 14:57:06] [debug]: updateNoteText:  false
[Dez 17 14:57:06] [debug]: setCurrentNote  - 'note':  Note: <id>19 <name>"Note 2019-12-17T14.55.21" <fileName>"Note 2019-12-17T14.55.21.md" <noteSubFolderId>1 <relativePath>"technisches" <hasDirtyData>false  - 'updateNoteText':  false  - 'updateSelectedNote':  true
[Dez 17 14:57:06] [debug]:  added to history:  NoteHistoryItem: <noteName>"Note 2019-12-17T14.55.21" <noteSubFolderPathData>"technisches" <cursorPosition>56 <relativeScrollBarPosition>0
[Dez 17 14:57:06] [debug]: Reply from  "/ocs/v2.php/apps/files_sharing/api/v1/shares"
[Dez 17 14:57:06] [debug]: Reply from share api
[Dez 17 14:57:06] [debug]: updateNoteShareStatusFromShare  - 'status':  "ok\n"
[Dez 17 14:57:08] [debug]: notesDirectoryWasModified:  "/home/ilukic/Notes"
[Dez 17 14:57:08] [status]: Notizordner wurde extern verändert
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  0
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  1
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  2
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  3
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  4
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  5
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  6
[Dez 17 14:57:08] [debug]: buildNotesIndex  - 'noteSubFolderId':  7
[Dez 17 14:57:08] [debug]: setupNoteFolderTables  - 'database version':  13
[Dez 17 14:57:08] [debug]: cloudConnection:  CloudConnection: <id>1 <name>"Standard" <serverUrl>"https://owncloud.ivanlukic.de" <username>"ilukic" <priority>1
[Dez 17 14:57:08] [debug]: fetchShares  - 'url':  QUrl("https://owncloud.ivanlukic.de/ocs/v2.php/apps/files_sharing/api/v1/shares")
[Dez 17 14:57:08] [debug]: notesWereModified:  "Note 2019-12-17T14.55.21.md"
[Dez 17 14:57:08] [debug]: updateNoteText:  false
[Dez 17 14:57:08] [debug]: setCurrentNote  - 'note':  Note: <id>19 <name>"Note 2019-12-17T14.55.21" <fileName>"Note 2019-12-17T14.55.21.md" <noteSubFolderId>1 <relativePath>"technisches" <hasDirtyData>false  - 'updateNoteText':  false  - 'updateSelectedNote':  true
[Dez 17 14:57:08] [debug]:  added to history:  NoteHistoryItem: <noteName>"Note 2019-12-17T14.55.21" <noteSubFolderPathData>"technisches" <cursorPosition>56 <relativeScrollBarPosition>0
[Dez 17 14:57:08] [debug]: Reply from  "/ocs/v2.php/apps/files_sharing/api/v1/shares"
[Dez 17 14:57:08] [debug]: Reply from share api
[Dez 17 14:57:08] [debug]: updateNoteShareStatusFromShare  - 'status':  "ok\n"
[Dez 17 14:57:17] [debug]: notesDirectoryWasModified:  "/home/ilukic/Notes"
[Dez 17 14:57:17] [status]: Notizordner wurde extern verändert
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  0
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  1
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  2
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  3
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  4
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  5
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  6
[Dez 17 14:57:17] [debug]: buildNotesIndex  - 'noteSubFolderId':  7
[Dez 17 14:57:17] [debug]: setupNoteFolderTables  - 'database version':  13
[Dez 17 14:57:17] [debug]: cloudConnection:  CloudConnection: <id>1 <name>"Standard" <serverUrl>"https://owncloud.ivanlukic.de" <username>"ilukic" <priority>1
[Dez 17 14:57:17] [debug]: fetchShares  - 'url':  QUrl("https://owncloud.ivanlukic.de/ocs/v2.php/apps/files_sharing/api/v1/shares")
[Dez 17 14:57:17] [debug]: notesWereModified:  "Note 2019-12-17T14.55.21.md"
[Dez 17 14:57:17] [debug]: updateNoteText:  false
[Dez 17 14:57:17] [debug]: setCurrentNote  - 'note':  Note: <id>19 <name>"Note 2019-12-17T14.55.21" <fileName>"Note 2019-12-17T14.55.21.md" <noteSubFolderId>1 <relativePath>"technisches" <hasDirtyData>false  - 'updateNoteText':  false  - 'updateSelectedNote':  true
[Dez 17 14:57:17] [debug]:  added to history:  NoteHistoryItem: <noteName>"Note 2019-12-17T14.55.21" <noteSubFolderPathData>"technisches" <cursorPosition>56 <relativeScrollBarPosition>0
[Dez 17 14:57:17] [debug]: Reply from  "/ocs/v2.php/apps/files_sharing/api/v1/shares"
[Dez 17 14:57:17] [debug]: Reply from share api
[Dez 17 14:57:17] [debug]: updateNoteShareStatusFromShare  - 'status':  "ok\n"

grafik

Maybe this helps?

pbek commented 4 years ago

Can you please explain in more detail and step by step what you did, what happened and what you expected.

nils-se commented 4 years ago

I experience the same problem. I am willing to help. What information should I provide?

My problem:

Will the use of the API solve this problem or is it somethind else that needs fixing?

pbek commented 4 years ago

I sync my notes with Nextcloud (without the API) via a Nextcloud synced Folder "Notes".

you mean you are using the Nextcloud sync client, right?

maybe a video would help to make more clear what you are doing

nils-se commented 4 years ago

you mean you are using the Nextcloud sync client, right?

maybe a video would help to make more clear what you are doing

yep, I use the Nextcloud sync client. I tried the Nextcloud integration but it didn't change the behaviour. Every 5-8 seconds the note is modifyed externally and my courser jumps to the beginning of the note. I had to change the settings back from "accept all external changes" to "ignore all external changes". This solves the problem and I will monitor the behaviour, if any conflicted copys will appear again. Thanks for your great app!

pbek commented 4 years ago

I tried the Nextcloud integration but it didn't change the behaviour.

which integration?

Every 5-8 seconds the note is modifyed externally and my courser jumps to the beginning of the note.

which operating system do you use? so far I've only seen such behavior on macOS

Thanks for your great app!

thank you :grin:

nils-se commented 4 years ago

integration: Nextcloud/owncloud-implementation with the QOwnNotes-API activated in the nextcloud-server-backend

OS: Kubuntu 18.04 with Nextcloud 2.6.2

pbek commented 4 years ago

integration: Nextcloud/owncloud-implementation with the QOwnNotes-API activated in the nextcloud-server-backend

the integration doesn't do any syncing

pbek commented 4 years ago

OS: Kubuntu 18.04 with Nextcloud 2.6.2

I've no problem on KDE Neon with Nextcloud. Do you still have the problem if you quit the Nextcloud sync client?

nils-se commented 4 years ago

If I pause the sync the problem stops. ("accept all external changes" activated)

pbek commented 4 years ago

("accept all external changes" activated)

do you need that settings if sync is deactivated?

nils-se commented 4 years ago

do you need that settings if sync is deactivated? no, I tested it now and if Nextcloud sync is deactivated, there is no problem. So far I have got no conflicted Notes. I hope it stays this way :)

pbek commented 4 years ago

ok, I'm closing this meanwhile

marisradu commented 4 years ago

In my case this happens all the time when the note is edited while the "notes directory" is kept in sync by a cloud provider app, in my case pCloud. I guess the same happened to @nils-se with the nextcloud sync client app.

It seems there is a race condition here: Peek 2020-01-17 15-23

Note that the last char I typed in the video was "a" and that is the letter highlighted on the "diff" screen, the external editor missed that last letter, while the internal one does have it, and instead I get a line break.

Not sure how can this be handled by QOwnNotes itself, but let's see if there is something that can be improved here. Let me know if I can provide more info (debug) or run any tests.

marisradu commented 4 years ago

Found another thing of interest here. This only happens when the notes folder is top level in the sync config, but does not happen if the notes directory is nested at least one level down, at least in my pCloud case.

I mean if I set-up this sync pCloud/Documents/Notes <> /home/radu/Documents/Notes and use /home/radu/Documents/Notes as notes directory, then the problem is there all the time. But if I create a sub-directory /home/radu/Documents/Notes/QOwnNotes and use that as the notes directory then there problem is gone.

Might be that on the top level of a synced directory the sync clients are doing more things that on the nested ones. So users of for example Dropbox if they encounter this error, would be worth knowing/trying if the notes directory is the Dropbox one or a sub-directory of it.

CraftingGamerTom commented 4 years ago

@pbek Why are you closing this? This is a very frustrating issue. Pops up every 2 minutes. Sounds dangerous to just accept all external changes, no? Is there risk of data loss with this race condition?

pbek commented 4 years ago

This only happens when the notes folder is top level in the sync config, but does not happen if the notes directory is nested at least one level down, at least in my pCloud case.

Nextcloud keeps some sync files in their root folder. If you don't want that to trigger note folder reloads then I guess it's best to turn off detection of external changes in the General settings.

@pbek Why are you closing this? This is a very frustrating issue. Pops up every 2 minutes. Sounds dangerous to just accept all external changes, no? Is there risk of data loss with this race condition?

I know nothing about your issue yet. Would you be so kind and explain in more detail and step by step what you did, what happened and what you expected. Can you please post the output from the debug settings (see issue template). And is there any useful log output if you enable the log panel (see Window / Panels)? Please make sure you also enable debug logging.

mcmc commented 4 years ago

Hi, I am a brand new user, but I seem to be having the same issue. And it is much more frequent than every 2 minutes.

I am not using Nextcloud or Dropbox or any other syncing tool. I didn't even have a ~/Nextcloud directory until it was created by QOwnNotes a few minutes ago, so it's hard to imagine that another app is modifying anything there. I am on a Mac, 10.14.16. My machine is busy with various tasks, however, so there could be OS-induced delays happening.

I downloaded the app earlier today. The only thing I changed in the preferences was a bunch of hot key shortcuts (mostly turning them off). I clicked the "empty page" icon in the upper left to make my first note, and started typing.

The panel comes up roughly once per line, but irregularly. It highlights the last few characters I typed in pink. No matter whether I click "Yes" or "No", the pink characters (which I just typed) remain in the document. Actually, after more cases, sometimes pink only stays if I click "yes". And once I got a blue character (maybe after hitting backspace to fix a typo? I don't remember).

Here are the lines I typed, after I gave up on writing my own notes and instead focused on the bug. Each line continues until the bug occurs. (Except the line of numbers.) So you can see it is really happening all the time.

  1. Item number three to see if it triggers the bug¶
  2. No, I'm not sure what triggers the bug... I¶
  3. 1234567890123456789012345678901234567890123456789012345678901234567890¶
  4. On that line, the bug didn't occur at all!¶
  5. Ok! Now, what are we going to do? I don't know! The

Just to be safe, I'm now trying without numbering. Let's see if the bu Yep, there's the bug again. Ok, how long will I have to type this time until I see the bug? Who knows! Wow, this is Ok, that time, the "a" seemed to disappear when I clicked on "yes", but prev Aha! That time I clicked "yes", and "iousl" (the last few characters in pink) got deleted! So at least now I can tell that the "external changes" are simply a slightly out-of-date version of the file. That sentence ended norma but the bug still occurred at the end of it. This sentence has had no b Oh that was nifty, this time the "b" was in blue! First time se That time it kept the pink. I was trying to say that that was the first time I saw blue text. Hmm, this line is getting really long! What, doesn't the bug like me anymore? Come on bug Yay, the bug came back! Let's see how long it will wait this

[here I turned on Window | Panels | Show Log Panel]

Ok, let's see if we get a log message when Ok, let's try again and see if we get a log message when the bug occurs. Yes, we seem to get the bug when we get the message "[status] Stored 1 note(s) to disk". But only if I am actively typing at that instant, it seems, but this i

On another topic (maybe), if I type a lot of "alsdfj" quickly, I get a lot of log messages like [15:08:36] [warning] Called attribute on invalid object: 2147519654 (two per invalid object number). But, back to the main topic, if I type it just at a continuous medium-low speed, I get the bug about 50% of the times it tries to save the file.

I value very much the feature of noticing external changes and showing the diff and letting the user choose what to do. So, if possible, I would rather not "solve" this problem by just turning off the feature.

If I do turn off the feature (so that I can actually try out the app), is there any way to turn it back on (for example to test the feature in the future)?

pbek commented 4 years ago

As long as an external process is writing anywhere in the note folder (and that can happen very likely under macos) the note folder needs to be reloaded and there will be discrepancy on what's on your disk (in the note file) and what's in your note edit panel. This discrepancy is summoning the dialog. I've yet no idea how to get around that. Ideas / pull requests welcome.

mcmc commented 4 years ago

Hmm, actually I would be surprised if an external process is writing there. There's hardly anything there (just 5 files, no hidden files, and the largest is just 37k), so any background process should finish almost instantly, and instead get bogged down in my hundreds of thousands of other files. Checking it out, I see that from ~/Nextcloud on down, no file or directory has been modified in hours, except for ~/Nextcloud/Notes/Note 2020-06-23T12.59.35.md, which is the one I am typing into. Any time I start typing, the bug happens, and still all modification dates are unchanged (except for the file it is saving).

I'm a bit confused -- when it saves, of course there is a discrepancy between the note edit panel and the file on disk (namely the recent typing) -- that's why it's saving. And I'd guess there is no discrepancy between the file on disk and the file as last saved.

In practice, the discrepancy that it complains about is just a fraction of a second of typing, far less than what was typed since the last save (which is more like ten seconds ago). So somehow, there are two almost-simultaneous "snapshots" of the text, being used for saving and/or comparison. It thinks these two should be the same if no third party is altering the file, but unfortunately the two can also differ due to an inopportune arrival of keystrokes. Surely the bug is that these two snapshots are not in fact simultaneous? Strangely, it logs "Stored 1 note(s) to disk" and then a second later it logs "Current note was modified externally". But why would it be comparing the-file-it-just-saved-a-second-ago to the-current-note-edit-panel-contents? That seems like a check for fast typing rather than a check for external manipulation (which matches my experience), but probably I am misunderstanding the situation.

Trying to follow the build instructions in the ReadMe, I downloaded the project and QT Creator (which I have not used before), but I am stuck at the step "build and run", which QT Creator refuses to do, because the project "is not configured". The "configure project" window lets me "add kits" (however, "no suitable kits found") or "import a build" (which prompts me to choose a file), but I don't know what a "kit" or "build" would look like, or if that is even the right solution.

pbek commented 4 years ago

Are there no Kits you can choose from?

image

mcmc commented 4 years ago

Interesting, after restarting Qt Creator a couple of these did show up, but they were still not usable. It turns out the default install is not sufficient -- it only installed Qt Creator, without any Qt Versions. Thanks for pointing me in the right direction, from here I was able to google my way to getting things working. Some comments:

When configuring, I got this, although I would not expect any android stuff be involved:

Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable to point to your Android NDK. Could not read qmake configuration file /Volumes/LaCie/Qt-2020/5.15.0/android/mkspecs/android-clang/qmake.conf. Project MESSAGE: Currently in DEBUG mode.

When building, I get about 100 warnings (deprecated, unused, etc.), but no errors.

When finally running it (the debug version), I do not get the "called attribute on invalid object" errors anymore, but I am still able to trigger the "Note was modified externally!" bug. So things are looking good.

I'll let you know if I figure anything out. :-)

pbek commented 4 years ago

Good job! Happy hunting :grin:

pbek commented 4 years ago

@mcmc, there also is an open issue of that kind here: #1763

mcmc commented 4 years ago

Yes, it looks just the same.

pbek commented 2 years ago

Maybe https://github.com/pbek/QOwnNotes/issues/2027#issuecomment-954609954 can help.