Bug 285083 - KRunner: KSycoca database changes don't propagate to ThreadWeaver threads
Summary: KRunner: KSycoca database changes don't propagate to ThreadWeaver threads
Status: RESOLVED FIXED
Alias: None
Product: krunner
Classification: Plasma
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources All
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
: 341693 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-10-27 11:04 UTC by Krzysztof Nowicki
Modified: 2015-09-19 08:34 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Nowicki 2011-10-27 11:04:37 UTC
Version:           unspecified (using Devel) 
OS:                All

The initial problem I encountered is that KRunner doesn't show newly installed applications. This seems to happen randomly and I've seen some bug reports about this, which were rejected as this sometimes just works. I took the liberty to do some deeper investigation and found a problem.

When the syscoca database is updated, kbuildsycoca emits the notifyDatabaseChanged signal over DBus to all KDE applications, so that they have a chance to refresh their cached copy of the database. In every application using KSycoca this is handled by a signal handler in the KSycoca class (KSycoca::notifyDatabaseChanged), which is connected to the DBus signal in the constructor. Since the KSycoca class is a per-thread singleton, such a connection is established in each thread that is using the sycoca database. When the DBus signal is emitted, it is dispatched to all the threads, which have a chance to destroy all sycoca factories thus cleaning any cache.

Unfortunately when an application also uses the ThreadWeaver library and uses KSycoca from the worker threads things go wrong, because Qt asynchronous signals are not dispatched to ThreadWeaver worker threads. In such case the sycoca factories created in those threads are not cleaned up after a database update and any jobs using KSycoca factories still use the old database.

Reproducible: Always

Steps to Reproduce:
1. Start a fresh Krunner instance
2. Show the Krunner window and type some letters to launch a non-existing application (for example 'gwe' for Gwenview). The application doesn't show up on the list.
3. Hide Krunner window by pressing Esc or close button.
4. Install the application attempted at step 2 (in this case Gwenview).
5. Repeat step 2 a couple of times (depends on the number of CPUs in the system)

Actual Results:  
On my system (4 cores) in 1/4 cases typing the letters will show no results. Otherwise the application button will show.

Expected Results:  
The application button should always show.

Repeating step 2. a couple of times before installing the application increases the chance of reproducing the problem. This is due to the fact that the jobs are dispatched randomly to the worker threads.
Comment 1 Krzysztof Nowicki 2011-10-27 11:08:00 UTC
I forgot to indicate that in the KDE version field: I'm using a snapshot of the 4.7 branch. 

The build and investigation was done on MS Windows, but I also experience this problem on a Linux platform.
Comment 2 Christoph Feck 2011-10-27 18:05:12 UTC
Nice investigation, thanks!
Comment 3 Vishesh Handa 2015-06-12 22:26:34 UTC
This is still a problem wtih Plasma 5.3.

Currently searching a few times makes the application popup as the SearchRunner has an internal event loop, so every thread which the SearchRunner runs on, gets their ksycoca db updated. And then if the services runner searches on that thread, it gets the correct results.
Comment 4 Vishesh Handa 2015-06-12 22:47:08 UTC
*** Bug 341693 has been marked as a duplicate of this bug. ***
Comment 5 David Faure 2015-09-19 08:34:20 UTC
This was fixed in ddd57bccdff99eea813b1ccee4d7071dd3978cd7 of kservice.git,
reviewboard 124607, KF 5.14.x.