QMYSQL SIGSEGV
-
Hallo
I got some failures with QMYSQL (QSQLITE will work)
My connection will be
if (dbType == "QSQLITE") { currentConnection = QSqlDatabase::addDatabase("QSQLITE", "CN"); currentConnection.setDatabaseName(QString(dataDir + "/%1-%2.db").arg(date.year()).arg(basename)); } else if (dbType == "QMYSQL") { QString userName = settings.value("DB_userName", "QRK").toString(); QString password = settings.value("DB_password", "").toString(); QString hostName = settings.value("DB_hostName", "localhost").toString(); currentConnection = QSqlDatabase::addDatabase("QMYSQL", "CN"); currentConnection.setHostName(hostName); currentConnection.setUserName(userName); currentConnection.setPassword(password); currentConnection.setConnectOptions("MYSQL_OPT_RECONNECT=1;MYSQL_OPT_CONNECT_TIMEOUT=86400;MYSQL_OPT_READ_TIMEOUT=60"); } bool ok = currentConnection.open();
When i was connected and to a simple query i got, but not allways a SIGSEGV. When i remove the connection options i got "Lost connection to MySQL server during query"
no matter if MySQL Server is localhost or any Server on the Internet.Yes, i search but found no solution. What can i do false?
OS: Linux Ubuntu (16.04 and 17.10) Server MariaDB from the Ubuntu Package
A Simply Query which returns one record and the Database holds max. 10 Entries.
QSqlDatabase dbc = QSqlDatabase::database("CN"); QSqlQuery query(dbc); query.prepare("SELECT strValue FROM globals WHERE name='shopName'"); query.exec(); query.next(); name = query.value(0).toString();
thx Chris
-
Hi,
What version of Qt are you using ?
-
Can you show the stack trace ?
By the way, 5.9.4 just got released, it's worth checking if it behaves better.
-
Hi
Hope this helps ...signal 11 (Speicherzugriffsfehler), address is 0x1b0 from 0x7fffcff1e5ea [bt]: (1) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x375ea) [0x7fffcff1e5ea] [bt]: (2) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x375ea) [0x7fffcff1e5ea] [bt]: (3) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x3865c) [0x7fffcff1f65c] [bt]: (4) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x2cbdc) [0x7fffcff13bdc] [bt]: (5) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x27516) [0x7fffcff0e516] [bt]: (6) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(mysql_stmt_prepare+0x96) [0x7fffcff0e8a6] [bt]: (7) /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so(+0xc70c) [0x7fffd050370c] [bt]: (8) /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5(_ZN10QSqlResult11savePrepareERK7QString+0x200) [0x7ffff64260d0] [bt]: (9) /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5(_ZN9QSqlQuery7prepareERK7QString+0x208) [0x7ffff6417008] [bt]: (10) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN8Database17getCashRegisterIdEv+0x80) [0x7ffff791f2aa] [bt]: (11) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN14VersionChecker10getVersionEv+0x25e) [0x7ffff7992e6a] [bt]: (12) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN9QtPrivate11FunctorCallINS_11IndexesListIJEEENS_4ListIJEEEvM14VersionCheckerFvvEE4callES7_PS5_PPv+0x7a) [0x7ffff7993e80] [bt]: (13) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN9QtPrivate15FunctionPointerIM14VersionCheckerFvvEE4callINS_4ListIJEEEvEEvS3_PS1_PPv+0x42) [0x7ffff7993e03] [bt]: (14) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN9QtPrivate11QSlotObjectIM14VersionCheckerFvvENS_4ListIJEEEvE4implEiPNS_15QSlotObjectBaseEP7QObjectPPvPb+0x6c) [0x7ffff7993d6d] [bt]: (15) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x97f) [0x7ffff5f729ff] [bt]: (16) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN6QTimer7timeoutENS_14QPrivateSignalE+0x37) [0x7ffff5f7f3b7] [bt]: (17) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN6QTimer10timerEventEP11QTimerEvent+0x28) [0x7ffff5f7f718] [bt]: (18) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN7QObject5eventEP6QEvent+0x9b) [0x7ffff5f7340b] [bt]: (19) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x9c) [0x7ffff6f0746c] [bt]: (20) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x2a4) [0x7ffff6f0ed34] [bt]: (21) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent+0x118) [0x7ffff5f43de8] [bt]: (22) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN14QTimerInfoList14activateTimersEv+0x40e) [0x7ffff5f9b91e] [bt]: (23) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(+0x2e20e1) [0x7ffff5f9c0e1] [bt]: (24) /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x2e7) [0x7ffff2a69fb7] [bt]: (25) /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x4b1f0) [0x7ffff2a6a1f0] [bt]: (26) /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x2c) [0x7ffff2a6a27c] [bt]: (27) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0x5f) [0x7ffff5f9c47f] [bt]: (28) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE+0x13a) [0x7ffff5f41e3a] [bt]: (29) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN7QThread4execEv+0x6a) [0x7ffff5d613ca] [bt]: (30) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(+0xac29d) [0x7ffff5d6629d] [bt]: (31) /lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc) [0x7ffff5aa27fc] [bt]: (32) /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f) [0x7ffff5232b5f]
lg Chris
-
Hi
Hope this helps ...signal 11 (Speicherzugriffsfehler), address is 0x1b0 from 0x7fffcff1e5ea [bt]: (1) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x375ea) [0x7fffcff1e5ea] [bt]: (2) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x375ea) [0x7fffcff1e5ea] [bt]: (3) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x3865c) [0x7fffcff1f65c] [bt]: (4) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x2cbdc) [0x7fffcff13bdc] [bt]: (5) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x27516) [0x7fffcff0e516] [bt]: (6) /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(mysql_stmt_prepare+0x96) [0x7fffcff0e8a6] [bt]: (7) /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlmysql.so(+0xc70c) [0x7fffd050370c] [bt]: (8) /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5(_ZN10QSqlResult11savePrepareERK7QString+0x200) [0x7ffff64260d0] [bt]: (9) /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5(_ZN9QSqlQuery7prepareERK7QString+0x208) [0x7ffff6417008] [bt]: (10) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN8Database17getCashRegisterIdEv+0x80) [0x7ffff791f2aa] [bt]: (11) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN14VersionChecker10getVersionEv+0x25e) [0x7ffff7992e6a] [bt]: (12) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN9QtPrivate11FunctorCallINS_11IndexesListIJEEENS_4ListIJEEEvM14VersionCheckerFvvEE4callES7_PS5_PPv+0x7a) [0x7ffff7993e80] [bt]: (13) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN9QtPrivate15FunctionPointerIM14VersionCheckerFvvEE4callINS_4ListIJEEEvEEvS3_PS1_PPv+0x42) [0x7ffff7993e03] [bt]: (14) /home/chris/Dokumente/projects/qt/build-QRK-Desktop-Debug/qrkcore/libQrkCore.so.1(_ZN9QtPrivate11QSlotObjectIM14VersionCheckerFvvENS_4ListIJEEEvE4implEiPNS_15QSlotObjectBaseEP7QObjectPPvPb+0x6c) [0x7ffff7993d6d] [bt]: (15) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x97f) [0x7ffff5f729ff] [bt]: (16) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN6QTimer7timeoutENS_14QPrivateSignalE+0x37) [0x7ffff5f7f3b7] [bt]: (17) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN6QTimer10timerEventEP11QTimerEvent+0x28) [0x7ffff5f7f718] [bt]: (18) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN7QObject5eventEP6QEvent+0x9b) [0x7ffff5f7340b] [bt]: (19) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x9c) [0x7ffff6f0746c] [bt]: (20) /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x2a4) [0x7ffff6f0ed34] [bt]: (21) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN16QCoreApplication15notifyInternal2EP7QObjectP6QEvent+0x118) [0x7ffff5f43de8] [bt]: (22) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN14QTimerInfoList14activateTimersEv+0x40e) [0x7ffff5f9b91e] [bt]: (23) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(+0x2e20e1) [0x7ffff5f9c0e1] [bt]: (24) /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_dispatch+0x2e7) [0x7ffff2a69fb7] [bt]: (25) /lib/x86_64-linux-gnu/libglib-2.0.so.0(+0x4b1f0) [0x7ffff2a6a1f0] [bt]: (26) /lib/x86_64-linux-gnu/libglib-2.0.so.0(g_main_context_iteration+0x2c) [0x7ffff2a6a27c] [bt]: (27) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0x5f) [0x7ffff5f9c47f] [bt]: (28) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE+0x13a) [0x7ffff5f41e3a] [bt]: (29) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZN7QThread4execEv+0x6a) [0x7ffff5d613ca] [bt]: (30) /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(+0xac29d) [0x7ffff5d6629d] [bt]: (31) /lib/x86_64-linux-gnu/libpthread.so.0(+0x77fc) [0x7ffff5aa27fc] [bt]: (32) /lib/x86_64-linux-gnu/libc.so.6(clone+0x3f) [0x7ffff5232b5f]
lg Chris
@ckvsoft
At what precise point from your code does this SEGV occur? It looks like it's just in yourquery.prepare()
statement, without even getting as far as the execute, is that what you find stepping through?Also, why do you think you're having to specify all those timeout/reconnect options, else you say it loses connection. It shouldn't be losing connection anyway. Unless that's an artefact of an underlying problem which sometimes SEGVs and sometimes doesn't...
-
@JonB
This was a test while without these Options i got a "Lost connection to MySQL server during query" without SEGV but the Query was not made. The Server is running normaly without troubles Its a TCP connection while not on the same machine. I test an other Server with do the same. Tomorow i will test a localhost machine.Its not allways the same query and not allways the prepare. Sometimes it is by "QSqlQuery query(dbc)" and somtime by the exec.
-
What is that qrkcore library you are using ?
-
Well... To know whether it's an external library you are using or something you are implementing.
Do you have the same crash if you implement just a minimal application that connects to the database and does the queries ?
-
Hi
I connect to a localhost mysql server and itseems to work. When i has running in the background some sql queries and i do at the same time from other window with the same connection any queryit works.When i connect to a server via TCP it will crash.
Edit: Its also with localhost, but the time is a bit longer ;( -
Can you trigger also that when using an application that's not using the QSql** classes ?
-
I think i have found a solution ;-) Some Test will be good. I will enhance my tests.
The Idea i found by reading http://doc.qt.io/qt-5/threads-modules.htmlJust my Application worked since 2015 with QSQLITE without troubles. But some users will also use MySQL.
For the solution i have adapted a database manager for my requirement.
-
So you're using multiple threads to write to your database ?
-
@SGaist
Yes. I Import JSON Files with an Import Walter Thread. Wenn a File is copied in a Directory it will Import and created new sql entries.
Nur Why SQlite has no Troubles?
I will also Move long Working Stuff to threadOb they GUI you also can do some queries by clicking Buttons
-
I'd say pure luck.
Are you creating one connection per thread like suggested in the documentation ?
-
@SGaist
Yes. The DatabaseManager save the connections per thread into aQHash<QThread*, QHash<QString, QSqlDatabase> >
I have only one thread at a time wich write to the database. All others max. 4 to only select
Sorry for my "Austrian English" ;-) -
Can you show how your are setting up the connections ?
-
The first connection is in my first post
Than for every connection i callQSqlDatabase dbc = DatabaseManager::database("CN"); QSqlQuery query(dbc) . .
.
#include "databasemanager.h" #include <QSqlDatabase> #include <QMutexLocker> #include <QThread> #include <QSqlError> #include <QDebug> QMutex DatabaseManager::s_databaseMutex; QHash<QThread*, QHash<QString, QSqlDatabase> > DatabaseManager::s_instances; QSqlDatabase DatabaseManager::database(const QString& connectionName) { QMutexLocker locker(&s_databaseMutex); QThread *thread = QThread::currentThread(); // if we have a connection for this thread, return it QHash<QThread*, QHash<QString, QSqlDatabase> >::Iterator it_thread = s_instances.find(thread); if (it_thread != s_instances.end()) { QHash<QString, QSqlDatabase>::iterator it_conn = it_thread.value().find(connectionName); if (it_conn != it_thread.value().end()) { QSqlDatabase connection = it_conn.value(); // qDebug() << "Function Name: " << Q_FUNC_INFO << " found SQL connection instances Thread: " << thread->currentThreadId() << " Name: " << connectionName; if (connection.isValid()) return it_conn.value(); } } // otherwise, create a new connection for this thread QSqlDatabase connection = QSqlDatabase::cloneDatabase( QSqlDatabase::database(connectionName), QString("%1_%2").arg(connectionName).arg((int)thread)); // open the database connection // initialize the database connection if (!connection.open()) { // Todo: Exeption Handling qCritical() << "Function Name: " << Q_FUNC_INFO << connection.lastError().text(); return connection; } qDebug() << "Function Name: " << Q_FUNC_INFO << " new SQL connection instances Thread: " << thread->currentThreadId() << " Name: " << connectionName; s_instances[thread][connectionName] = connection; return connection; }
#ifndef DATABASEMANAGER_H #define DATABASEMANAGER_H #include "qrkcore_global.h" #include <QMutex> #include <QHash> #include <QSqlDatabase> class QThread; class QRK_EXPORT DatabaseManager { public: static QSqlDatabase database(const QString& connectionName = QLatin1String(QSqlDatabase::defaultConnection)); private: static QMutex s_databaseMutex; static QHash<QThread*, QHash<QString, QSqlDatabase>> s_instances; }; #endif // DATABASEMANAGER_H
I found the code and adapted it for my requirement.