Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. mysql driver crash when reconnecting to remote database from linux
Forum Updated to NodeBB v4.3 + New Features

mysql driver crash when reconnecting to remote database from linux

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 919 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    deleted602
    wrote on last edited by deleted602
    #1

    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]
    
    D 1 Reply Last reply
    0
    • D deleted602

      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]
      
      D Offline
      D Offline
      deleted602
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Pretty intriguing... How did you install the various versions of Qt ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • D Offline
          D Offline
          deleted602
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            deleted602
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved