Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-99326

With multi-threading, QSqlDatabase::open() randomly crashes on wrong host/port.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P1: Critical
    • None
    • 6.2.2
    • SQL Support
    • None
    • Windows 10, MSVC 2019
    • Windows

    Description

      The code to reproduce the bug:

      struct Cfg { QString drv, qname, host; int port; QString name, user, pass; };
      
      
      void createDestroyDb(const Cfg& c) { bool ok = false; QSqlDatabase d; for(;;) {
      d = QSqlDatabase::addDatabase(c.drv, c.qname); if(!d.isValid()) break;
      d.setHostName(c.host); d.setPort(c.port); d.setDatabaseName(c.name); d.setUserName(c.user); d.setPassword(c.pass);
      { /*static QMutex m; QMutexLocker l(&m);*/ ok = d.open(); } break; } // The QMutex hack suppresses the bug.
      if(!ok) qWarning().noquote() << d.lastError().text(); d = {}; QSqlDatabase::removeDatabase(c.qname); }
      
      
      void f() { std::vector<QString> v({"db1", "db2"});
      QtConcurrent::blockingMap(v, [](const QString& s) { createDestroyDb({"QPSQL", s, "wronghost", 5432, "db", "user", "pass"}); });
      qInfo("No crash happened."); }
      
      
      int main(int ac, char* av[]) {
      qSetMessagePattern("[%{if-warning} - - - WARN %{endif}%{time HHmmss.zzz} %{file}:%{line} %{function} %{threadid}] %{message}");
      QCoreApplication app(ac, av); QTimer::singleShot(0, [&] { f(); app.quit(); }); return app.exec(); }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            some_username Dmitriy Goncharov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes