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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P1: Critical
    • Resolution: Unresolved
    • Affects Version/s: 6.2.2
    • Fix Version/s: None
    • Component/s: SQL Support
    • Labels:
      None
    • Environment:
      Windows 10, MSVC 2019

      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

            Assignee:
            mabrand Mark Brand
            Reporter:
            some_username Dmitriy Goncharov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes