Skip reload when another reload is already in progress
AbandonedPublic

Authored by rkflx on Aug 28 2017, 11:34 PM.

Details

Reviewers
None
Group Reviewers
Okular
Summary

When pressing and holding F5, Okular would reload the current
document multiple times and eventually get stuck with no document
showing and the "Reloading the document..." message reappearing every
second in an infinite loop. On exit, Okular then would sometimes
segfault, although often in different lines of code.

These issues can be avoided by only allowing one reload progressing at
any time. Any further reload requests are discarded.

Note: The "Reload" menu entry and shortcut are already disabled while
fetching the document (most noticable when using a slow network link).
The new lock protects against *overlapping* reload requests coming in
after fetching completes but before rendering finishes.

Thanks to @aacid for finding the fix, this merely improves the
implementation by using RAII instead of a non-dry bool.

Test Plan
  • Builds with both GCC 4.8 / Qt 5.6 and GCC 7.1 / Qt 5.9.
  • No hiccups and crashes anymore when holding F5.
  • Behaviour for slow downloading remote documents unchanged.

Diff Detail

Repository
R223 Okular
Branch
reload-mutex (branched from Applications/17.08)
Lint
No Linters Available
Unit
No Unit Test Coverage
rkflx created this revision.Aug 28 2017, 11:34 PM
Restricted Application added a project: Okular. · View Herald TranscriptAug 28 2017, 11:34 PM

Using a mutex when threads are not involved is wrong in my book, and that's why my branch uses a bool as customary

Do you suggest I should write my own bool-based RAII wrapper, which would be racy, less efficient, buggy, more verbose and harder to read? Using a mutex solves the maintainability risk outlined in D7495#141032 with no costs. Also, when researching this, I got the impression that a mutex is more customary when locking is involved (which is what we are doing here).

aacid added a comment.Aug 29 2017, 9:31 PM

I don't suggest you write anything, there's aleady code that works in my patch and it's really much easier to understand what it does than this one.

rkflx added a comment.Aug 30 2017, 6:26 AM

I guess someone else should judge which is easier to read considering the full picture (I got confused by your areWeReloading naming, actually). I admit someone not familiar with std::mutex semantics would need to read the comment, but understanding a custom RAII wrapper is even harder.

Could you suggest another reviewer?

sander added a subscriber: sander.Aug 30 2017, 9:07 AM

From merely looking at the patches, I like this one better than Albert's. In Albert's patch, the fact that you have to set m_areWeReloading at every exit of the method slotDoFileDirty does feel like breakage waiting to happen.

On the other hand, Albert's objection "Using a mutex when threads are not involved is wrong in my book" is not without reason either. Casual readers of the code will see the mutex and expect there to be threading. I therefore suggest to expand the comment in part.cpp:1773 to clearly state why the mutex is needed, and why it does not have anything to do with threading.

Is that a reasonable compromise?

rkflx updated this revision to Diff 18960.Aug 30 2017, 1:05 PM
rkflx edited the summary of this revision. (Show Details)

Thanks Oliver, I like compromises. You inspired me to try another way: Out with the unique_lock<mutex>, in with the unique_ptr<bool>. This way no custom RAII wrapper is needed.

OTOH, I'm not really convinced there is no threading involved (or will be in the future). Anyway, I hope this is acceptable now.

To be honest, I liked your first patch better. Granted, that definition of reloadLock is elegant, but you need quite a bit of C++ experience to see its beauty. People without that will be scared.

But it is really Albert who decides.

rkflx abandoned this revision.Aug 31 2017, 6:15 AM