Bug 330215 - Crash in QPSQL driver when shutting down Akonadi
Summary: Crash in QPSQL driver when shutting down Akonadi
Status: RESOLVED FIXED
Alias: None
Product: Akonadi
Classification: Frameworks and Libraries
Component: server (show other bugs)
Version: 1.11.0
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: kdepim bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-20 17:25 UTC by Daniel Vrátil
Modified: 2014-01-20 17:39 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 1.11.1


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Vrátil 2014-01-20 17:25:01 UTC
QPSQL driver crashes when destroying QSqlQueries cached in QueryCache, because they are being destroyed after QSqlDatabase connection has been closed.

I think this is a bug in Qt because, because it should check whether QSqlDriver has already been deleted before using it. I checked Qt5 code and it should be fine there. Anyway we should 
workaround this in Akonadi.

    Program received signal SIGSEGV, Segmentation fault.
    parseInput (conn=conn@entry=0x40000000b) at fe-exec.c:1646
    1646            if (PG_PROTOCOL_MAJOR(conn->pversion) >= 3)
    (gdb) bt
    #0  parseInput (conn=conn@entry=0x40000000b) at fe-exec.c:1646
    #1  0x00007f5836497b08 in PQgetResult (conn=conn@entry=0x40000000b) at fe-exec.c:1722
    #2  0x00007f5836497d8f in PQexecStart (conn=conn@entry=0x40000000b) at fe-exec.c:1895
    #3  0x00007f5836497f41 in PQexec (conn=0x40000000b, query=0xd55a98 "DEALLOCATE qpsqlpstmt_e4") at fe-exec.c:1804
    #4  0x00007f58366bdd78 in QPSQLDriverPrivate::exec (this=0xda1870, stmt=<optimized out>) at ../../../sql/drivers/psql/qsql_psql.cpp:177
    #5  0x00007f58366be324 in QPSQLDriverPrivate::exec (this=0xda1870, stmt="DEALLOCATE qpsqlpstmt_e4") at ../../../sql/drivers/psql/qsql_psql.cpp:187
    #6  0x00007f58366be45e in qDeallocatePreparedStmt (d=d@entry=0xda14c0) at ../../../sql/drivers/psql/qsql_psql.cpp:288
    #7  0x00007f58366be877 in QPSQLResult::~QPSQLResult (this=0xf0fa90, __in_chrg=<optimized out>) at ../../../sql/drivers/psql/qsql_psql.cpp:309
    #8  0x00007f58366be8d9 in QPSQLResult::~QPSQLResult (this=0xf0fa90, __in_chrg=<optimized out>) at ../../../sql/drivers/psql/qsql_psql.cpp:312
    #9  0x0000003a7421182e in QSqlQuery::~QSqlQuery (this=0x40000000b, __in_chrg=<optimized out>) at kernel/qsqlquery.cpp:245
    #10 0x000000000057e3d5 in QHashNode<QString, QSqlQuery>::~QHashNode (this=0xd705a0) at /usr/include/QtCore/qhash.h:216
    #11 0x000000000057e3a5 in QHashNode<QString, QSqlQuery>::~QHashNode (this=0xd705a0) at /usr/include/QtCore/qhash.h:216
    #12 0x000000000057e32d in QHash<QString, QSqlQuery>::deleteNode2 (node=0xd705a0) at /usr/include/QtCore/qhash.h:521
    #13 0x0000003a6dc98799 in QHashData::free_helper (this=0xd77ff0, node_delete=0x57e310 <QHash<QString, QSqlQuery>::deleteNode2(QHashData::Node*)>) at tools/qhash.cpp:275
    #14 0x000000000057e364 in QHash<QString, QSqlQuery>::freeData (this=0xd70540, x=0xd77ff0) at /usr/include/QtCore/qhash.h:570
    #15 0x000000000057e576 in QHash<QString, QSqlQuery>::~QHash (this=0xd70540) at /usr/include/QtCore/qhash.h:283
    #16 0x000000000057e525 in QHash<QString, QSqlQuery>::~QHash (this=0xd70540) at /usr/include/QtCore/qhash.h:283
    #17 0x000000000057e4f8 in Cache::~Cache (this=0xd70530) at /home/progdan/projects/kde/akonadi/server/src/storage/querycache.cpp:34
    #18 0x000000000057de05 in Cache::~Cache (this=0xd70530) at /home/progdan/projects/kde/akonadi/server/src/storage/querycache.cpp:34
    #19 0x000000000057de29 in Cache::~Cache (this=0xd70530) at /home/progdan/projects/kde/akonadi/server/src/storage/querycache.cpp:34
    #20 0x000000000057e4a2 in qThreadStorage_deleteData<Cache> (d=0xd70530) at /usr/include/QtCore/qthreadstorage.h:97
    #21 0x000000000057e45f in QThreadStorage<Cache*>::deleteData (x=0xd70530) at /usr/include/QtCore/qthreadstorage.h:140
    #22 0x0000003a6dc7a44a in QThreadStorageData::finish (p=0xd51d98) at thread/qthreadstorage.cpp:203
    #23 0x0000003a6dd872d1 in QCoreApplicationPrivate::~QCoreApplicationPrivate (this=0xd51f90, __in_chrg=<optimized out>) at kernel/qcoreapplication.cpp:473
    #24 0x0000003a6dd874c9 in QCoreApplicationPrivate::~QCoreApplicationPrivate (this=0xd51f90, __in_chrg=<optimized out>) at kernel/qcoreapplication.cpp:490
    #25 0x0000003a6dd9e065 in cleanup (pointer=<optimized out>) at ../../src/corelib/tools/qscopedpointer.h:62
    #26 ~QScopedPointer (this=0xd51f78, __in_chrg=<optimized out>) at ../../src/corelib/tools/qscopedpointer.h:100
    #27 QObject::~QObject (this=0xd51f70, __in_chrg=<optimized out>) at kernel/qobject.cpp:816
    #28 0x0000003a6dd88249 in QCoreApplication::~QCoreApplication (this=0xd51f70, __in_chrg=<optimized out>) at kernel/qcoreapplication.cpp:865
    #29 0x00000000004a07fe in QScopedPointerDeleter<QCoreApplication>::cleanup (pointer=0xd51f70) at /usr/include/QtCore/qscopedpointer.h:62
    #30 0x00000000004a88bf in QScopedPointer<QCoreApplication, QScopedPointerDeleter<QCoreApplication> >::~QScopedPointer (this=0x7ffff65a2a70) at /usr/include/QtCore/qscopedpointer.h:100
    #31 0x00000000004a29a5 in QScopedPointer<QCoreApplication, QScopedPointerDeleter<QCoreApplication> >::~QScopedPointer (this=0x7ffff65a2a70) at /usr/include/QtCore/qscopedpointer.h:98
    #32 0x00000000004a1930 in AkApplication::~AkApplication (this=0x7ffff65a2a60) at /home/progdan/projects/kde/akonadi/shared/akapplication.cpp:45
    #33 0x00000000004a0825 in AkApplicationImpl<QCoreApplication>::~AkApplicationImpl (this=0x7ffff65a2a60) at /home/progdan/projects/kde/akonadi/shared/akapplication.h:84
    #34 0x00000000004a0275 in AkApplicationImpl<QCoreApplication>::~AkApplicationImpl (this=0x7ffff65a2a60) at /home/progdan/projects/kde/akonadi/shared/akapplication.h:84
    #35 0x000000000049ffac in main (argc=1, argv=0x7ffff65a2cb8) at /home/progdan/projects/kde/akonadi/server/src/main.cpp:83



Reproducible: Always

Steps to Reproduce:
1. Use QPSQL backend with Akonadi
2. Use Akonadi a little so that there are some queries in QueryCache
3. akonadictl stop
Actual Results:  
Crash

Expected Results:  
No crash
Comment 1 Daniel Vrátil 2014-01-20 17:39:30 UTC
Git commit fb8e5193cd62fa3b03837bf97472cbb8ba6f12c4 by Dan Vrátil.
Committed on 20/01/2014 at 18:38.
Pushed by dvratil into branch '1.11'.

Clear cached queries before closing database connection

This works around a crash in QPSQL driver in Qt 4, where destroying QSqlQuery
after QSqlDatabase connection has been closed apparently leads to a crash.

We now clear all cached QSqlQueries belonging to the same thread as the
DataStore being destroyed before it closes the connection.
FIXED-IN: 1.11.1

M  +1    -1    server/control/agentmanager.cpp
M  +2    -0    server/src/storage/datastore.cpp
M  +10   -0    server/src/storage/querycache.cpp
M  +3    -0    server/src/storage/querycache.h

http://commits.kde.org/akonadi/fb8e5193cd62fa3b03837bf97472cbb8ba6f12c4