Unsolved mysql driver crash when reconnecting to remote database from linux
-
I have some trouble with the mysql driver under linux. Whenever I try to reconnect to a remote database it crashes with segfault. I'm starting to run out of ideas.
After doing some searhing I found these, but they didn't help me solve the issue:
https://stackoverflow.com/questions/15740587/mysql-multithreading-app-and-segfault-when-reconnect-to-mysql-into-worker-thread (though I'm not explicitly using threads, I guess Qt does something similar behind the curtain, as the stack contains a mutex call)
https://stackoverflow.com/questions/43367618/reopening-mysql-connection-causes-segfault same problem here when the database is not on localhost.
Here's my dummy code to reproduce the issue:
#include <QCoreApplication> #include <QtSql> #include <QtConcurrent> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); auto host = "localhost"; //auto host = "192.168.137.42"; { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "test"); db.setHostName(host); db.setPort(3306); db.setUserName("usr"); db.setPassword("pwd"); db.setDatabaseName("db"); qDebug() << "Open: " << db.open(); QSqlQuery q("SHOW VARIABLES LIKE '%version%';", db); while(q.next()) { qDebug() << q.value(0).toString() << " = " << q.value(1).toString(); } } QSqlDatabase::removeDatabase("test"); { QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", "test2"); db.setHostName(host); db.setPort(3306); db.setUserName("usr"); db.setPassword("pwd"); db.setDatabaseName("db"); qDebug() << "Open: " << db.open(); } QSqlDatabase::removeDatabase("test2"); qDebug() << "Done"; return a.exec(); }
Running on ubuntu with database on host OS (macOS):
"innodb_version" = "5.7.24" "protocol_version" = "10" "slave_type_conversions" = "" "tls_version" = "TLSv1,TLSv1.1,TLSv1.2" "version" = "5.7.24" "version_comment" = "Homebrew" "version_compile_machine" = "x86_64" "version_compile_os" = "osx10.14" Program received signal SIGSEGV, Segmentation fault. __GI___pthread_mutex_lock (mutex=0x20) at ../nptl/pthread_mutex_lock.c:65 65 ../nptl/pthread_mutex_lock.c: No such file or directory. (gdb) bt #0 __GI___pthread_mutex_lock (mutex=0x20) at ../nptl/pthread_mutex_lock.c:65 #1 0x00007ffff36bd3fa in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 #2 0x00007ffff3697963 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 #3 0x00007ffff366f812 in mysql_real_connect () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20 #4 0x00007ffff3a4ea43 in QMYSQLDriver::open(QString const&, QString const&, QString const&, QString const&, int, QString const&) () from /home/thomas/Qt/5.9.7/gcc_64/plugins/sqldrivers/libqsqlmysql.so #5 0x00007ffff7d9bba0 in QSqlDatabase::open() () from /home/thomas/Qt/5.9.7/gcc_64/lib/libQt5Sql.so.5 #6 0x0000555555556879 in main (argc=1, argv=0x7fffffffdf28) at ../thread-this/main.cpp:36
Running on ubuntu with database on localhost
"innodb_version" = "5.7.24" "protocol_version" = "10" "slave_type_conversions" = "" "tls_version" = "TLSv1,TLSv1.1" "version" = "5.7.24-0ubuntu0.18.10.1" "version_comment" = "(Ubuntu)" "version_compile_machine" = "x86_64" "version_compile_os" = "Linux" # No SIGSEGV
When running the actual application (not the dummy project) in docker I get this stacktrace:
mysrv_1 | 03/01/19 15:05:53.987 14 ?mysrv?|qt_message_output|QDebug::~QDebug Signal triggered: 11 - SIGSEGV mysrv_1 | 03/01/19 15:05:53.988 14 ?mysrv?|qt_message_output|QDebug::~QDebug Stacktrace: mysrv_1 | ./mysrv() [0x591303] mysrv_1 | ./mysrv() [0x5916b3] mysrv_1 | /lib/x86_64-linux-gnu/libc.so.6(+0x354b0) [0x7f8ea22fa4b0] mysrv_1 | /lib/x86_64-linux-gnu/libpthread.so.0(pthread_mutex_lock+0x4) [0x7f8ea2f39d44] mysrv_1 | /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x85879) [0x7f8e9b8d5879] mysrv_1 | /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(+0x5c110) [0x7f8e9b8ac110] mysrv_1 | /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20(mysql_real_connect+0x15f6) [0x7f8e9b8820d6] mysrv_1 | /opt/qt59/plugins/sqldrivers/libqsqlmysql.so(+0x97f2) [0x7f8ea48c97f2] mysrv_1 | /opt/qt59/lib/libQt5Sql.so.5(_ZN12QSqlDatabase4openERK7QStringS2_+0x5e) [0x7f8ea49d7fee] mysrv_1 | ./mysrv() [0x59d5a4] mysrv_1 | ./mysrv() [0x59a715] mysrv_1 | ./mysrv() [0x6000bd] mysrv_1 | ./mysrv() [0x69baca] mysrv_1 | ./mysrv() [0x45e60e] mysrv_1 | /opt/qt59/lib/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x9a6) [0x7f8ea34078b6]
-
It seems to work fine with qt 5.10.1 (haven't tested 5.10.0). I tried searching for solved bugs between 5.9.7 and 5.10.1 but I haven't found anything that that looks related.
-
Hi,
Pretty intriguing... How did you install the various versions of Qt ?
-
Qt was installed by using the official installer. I had to build QMYSQL myself because of wrong dynamic linking to libmysqclient.
I'm starting to suspect that the database is the problem. I tried connecting to a different remote database, and that worked without problems. It's still weird that running it in docker fails too. But this is on the same host as the problematic mysql database, so who knows :P
-
I have created a (non) working example to reproduce it. It's docker based, and only requires a couple of commands in order to run / fail.
It's available here (with documentation in README): https://github.com/tskardal/mysigsegv