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

Sync race between qown <-> nextcloud client #1041

Closed
cls-nebadje opened this Issue Oct 7, 2018 · 13 comments

Comments

Projects
None yet
2 participants
@cls-nebadje

cls-nebadje commented Oct 7, 2018

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 pbek added the question label Oct 7, 2018

@pbek

This comment has been minimized.

Owner

pbek commented Oct 7, 2018

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

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

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

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

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

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

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

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

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

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

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

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

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

@pbek

This comment has been minimized.

Owner

pbek commented Oct 7, 2018

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.

QString text1 = this->ui->noteTextEdit->toPlainText();

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

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

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

@cls-nebadje

This comment has been minimized.

cls-nebadje commented Oct 7, 2018

@pbek pbek added enhancement and removed question labels Oct 8, 2018

@pbek

This comment has been minimized.

Owner

pbek commented Oct 8, 2018

18.10.1

  • changes of the current note outside of QOwnNotes will now not trigger the
    The current note was modified outside of this application! dialog while
    editing the current note if the content of the note file wasn't really
    modified (for #1041)
    • this was a problem because the Nextcloud / ownCloud sync client seems
      to write to the note files on some systems even if there were no actual
      changes to be made, this spawned the dialog if the user was actively
      editing the note
@pbek

This comment has been minimized.

Owner

pbek commented Oct 8, 2018

maybe the same issue like in #171

pbek added a commit that referenced this issue Oct 9, 2018

@pbek

This comment has been minimized.

Owner

pbek commented Oct 9, 2018

@cls-nebadje, @minthemiddle

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

@pbek pbek closed this Oct 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment