Reopening mysql connection causes segfault

402
April 12, 2017, at 3:43 PM

Simple application causes segfault when I try to connect to the same database twice. It works fine with local database but crashes on second call to open() with any remote tunnel. What could be the cause? Am I doing something I should not be doing?

Obviously this is made up example but in reality I'm trying to manage db connections for a bigger app and manager does similar open/close cycle when requested.

QT version is 5.7.0. Compiled from sources to get better stack trace but not sure if it helped.

Remote MySQL is 5.6.27 (Amazon RDS actually), local is 5.7.17.

It's not eactly happening because I use tunnels. I can create a tunnel to my local database and the app works fine, no crashes.

If I tunnel local database to remote machine and then tunnel back from it to local, app still works. So it's not the latency either.

Code:

#include <QCoreApplication>
#include <QSqlDatabase>
void initDb(QSqlDatabase db) {
    QString connectionHost = "127.0.0.1";
    int port = 3311; // local tunnel
    QString user = "mydbuser";
    QString password = "mydbpassword";
    QString database = "mydbname";
    db.setHostName(connectionHost);
    db.setPort(port);
    db.setUserName(user);
    db.setPassword(password);
    db.setDatabaseName(database);
}
int main(int argc, char *argv[]) {
    QString name1 = "db1", name2 = "db2";
    {
        QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL", name1);
        initDb(db);
        db.open();
        db.close();
    }
    QSqlDatabase::removeDatabase(name1);
    {
        QSqlDatabase db1 = QSqlDatabase::addDatabase("QMYSQL", name2);
        initDb(db1);
        db1.open();
        db1.close();
    }
    QSqlDatabase::removeDatabase(name2);
    return 0;
}

Trace:

Thread 1 (Thread 0x7f7603ee3740 (LWP 3505)):
#0  __GI___pthread_mutex_lock (mutex=0x20) at ../nptl/pthread_mutex_lock.c:67
    __PRETTY_FUNCTION__ = "__pthread_mutex_lock"
    type = <optimized out>
    id = <optimized out>
#1  0x00007f75ff228d79 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#2  0x00007f75ff1ff660 in ?? () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#3  0x00007f75ff1d65e5 in mysql_real_connect () from /usr/lib/x86_64-linux-gnu/libmysqlclient.so.20
No symbol table info available.
#4  0x00007f7603f06a54 in QMYSQLDriver::open (this=0xbd4c90, db=..., user=..., password=..., host=..., port=3311, connOpts=...) at ../../../sql/drivers/mysql/qsql_mysql.cpp:1393
    d = 0xbd5ea0
    optionFlags = 65536
    opts = {<QList<QString>> = {<QListSpecialMethods<QString>> = {<No data fields>}, {p = {static shared_null = {ref = {atomic = {_q_value = {<std::__atomic_base<int>> = {static _S_alignment = 4, _M_i = -1}, <No data fields>}}}, alloc = 0, begin = 0, end = 0, array = {0x0}}, d = 0x7f7603b0ffb0 <QListData::shared_null>}, d = 0x7f7603b0ffb0 <QListData::shared_null>}}, <No data fields>}
    unixSocket = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
    sslCert = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
    sslCA = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
    sslKey = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
    sslCAPath = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
    sslCipher = {static null = {<No data fields>}, d = 0x7f7603b0c140 <QArrayData::shared_null>}
    reconnect = 0 '\000'
    connectTimeout = 0
    readTimeout = 0
    writeTimeout = 0
    __PRETTY_FUNCTION__ = "virtual bool QMYSQLDriver::open(const QString&, const QString&, const QString&, const QString&, int, const QString&)"
    mysql = 0x7ffe4d0aee80
#5  0x00007f7603f2d4b9 in QSqlDatabase::open (this=0x7ffe4d0aef70) at kernel/qsqldatabase.cpp:835
No locals.
#6  0x00000000004010d0 in main (argc=1, argv=0x7ffe4d0af098) at ../main.cpp:31
    db1 = {static defaultConnection = 0x7f7603f52bf5 "qt_sql_default_connection", d = 0xbbdee0}
    name1 = {static null = {<No data fields>}, d = 0xbbde50}
    name2 = {static null = {<No data fields>}, d = 0xbbde80}
Rent Charter Buses Company
READ ALSO
Hadoop - No route to host while configuring HUE

Hadoop - No route to host while configuring HUE

I have installed hue on my local ubuntu system and installed hadoop muti cluster system on two system

447
How to store address in database?

How to store address in database?

I have laravel application where user can select address

302
Real time notifications in Laravel 5

Real time notifications in Laravel 5

I'm currently working on notification system in Laravel,Can anyone suggest me best tutorials or documentation for real time Notifications in Laravel

357