Bug 400723 - Journal filled with QSqlDataBasePrivate warning messages when using krunner
Summary: Journal filled with QSqlDataBasePrivate warning messages when using krunner
Status: RESOLVED FIXED
Alias: None
Product: frameworks-krunner
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: 5.51.0
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Kai Uwe Broulik
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-06 01:12 UTC by Stefan Brüns
Modified: 2018-11-14 23:55 UTC (History)
0 users

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stefan Brüns 2018-11-06 01:12:05 UTC
SUMMARY



STEPS TO REPRODUCE
1. Open krunner
2. type some seach term (>= 3 letters)
3. close krunner again

OBSERVED RESULT
After closing, each time 4 warning messages are added to the journal:

QSqlDatabasePrivate::removeDatabase: connection '.../places.sqlite' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name '.../places.sqlite', old connection removed.
QSqlDatabasePrivate::removeDatabase: connection '.../favicons.sqlite' is still in use, all queries will cease to work.
QSqlDatabasePrivate::addDatabase: duplicate connection name '.../favicons.sqlite', old connection removed.


EXPECTED RESULT
Warnings should be fixed


SOFTWARE VERSIONS
(available in About System)
KDE Plasma Version: 5.14.2
KDE Frameworks Version: 5.51
Qt Version: 5.11.2

ADDITIONAL INFORMATION
Comment 1 Stefan Brüns 2018-11-14 23:55:57 UTC
Git commit 145caeac105043d2d0bfba40717e9ed336471ccf by Stefan Brüns.
Committed on 14/11/2018 at 23:55.
Pushed by bruns into branch 'master'.

[Bookmarks Runner] Open database connection in the query thread

Summary:
QSqlDatabase connection instances are global reference counted objects which
can be crated using the QSqlDatabase::addDatabase(...) method and later
retrieved with QSqlDatabase::database(connectionname).

Connections should only be used from a single thread, and should be cleaned
up with QSD::removeDatabase(name), which implicitly closes the connection
when the last reference is removed.

Currently, the same connection (name) is reused over all threads, and
the connection is only removed implicitly by replacing it via addDatabase().
This leads to warnings, i.e.: "QSqlDatabasePrivate::addDatabase: duplicate
connection name '...', old connection removed."

As one reference is held by the m_db member, the implicit removal triggers
another warning: "QSqlDatabasePrivate::removeDatabase: connection '..."
is still in use, all queries will cease to work."

According to the documentation, "It is highly recommended that you do not
keep a copy of the QSqlDatabase around as a member of a class, as this
will prevent the instance from being correctly cleaned up on shutdown."
There is no need to keep a reference using a member variable, as retrieving
an open connection via QSqlDatabase::database(...) is cheap.

Create a per-thread DB connection on first use, and remove the connections
when the FetchSqlite instance is torn down.

Delaying the open is beneficial for the favicon instance, which may be
unused when the icon is already cached on disk.

See also T9626.

Test Plan:
execute a query in krunner
1. Results are as expected
2. The 'QSqlDatabasePrivate::removeDatabase: connection ... is still in use,
   all queries will cease to work.' warning no longer appears
3. The 'QSqlDatabasePrivate::addDatabase: duplicate connection name ...,
   old connection removed' warning no longer appears

Reviewers: #frameworks, mart

Reviewed By: mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D16409

M  +43   -16   runners/bookmarks/fetchsqlite.cpp
M  +0    -1    runners/bookmarks/fetchsqlite.h

https://commits.kde.org/plasma-workspace/145caeac105043d2d0bfba40717e9ed336471ccf