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

QDBusConnection::sessionBus() is not threadsafe

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.3.0
    • D-Bus
    • None
    • Linux, X11, helgrind

    Description

      Calling sessionBus() in multiple threads simultaneously leads to

      ==16679== Possible data race during read of size 8 at 0x8220AE0 by thread #2
      ==16679== Locks held: none
      ==16679==    at 0x7F8EAF8: QDBusConnection::QDBusConnection(QDBusConnection const&) (qdbusconnection.cpp:268)
      ==16679==    by 0x7F90BA1: QDBusConnection::sessionBus() (qdbusconnection.cpp:1092)
      ==16679== 
      ==16679== This conflicts with a previous write of size 8 by thread #3
      ==16679== Locks held: 1, at address 0x8220A80
      ==16679==    at 0x7F8EAFF: QDBusConnection::QDBusConnection(QDBusConnection const&) (qdbusconnection.cpp:268)
      ==16679==    by 0x7F8EE07: QDBusConnection::connectToBus(QDBusConnection::BusType, QString const&) (qdbusconnection.cpp:355)
      ==16679==    by 0x7F91D06: QDBusDefaultConnection::QDBusDefaultConnection(QDBusConnection::BusType, char const*) (qdbusconnection.cpp:1062)
      ==16679==    by 0x7F909CF: (anonymous namespace)::Q_QGS__q_sessionBus::innerFunction()::Holder::Holder() (qdbusconnection.cpp:1078)
      ==16679==    by 0x7F90A3C: (anonymous namespace)::Q_QGS__q_sessionBus::innerFunction() (qdbusconnection.cpp:1078)
      ==16679==    by 0x7F90D6D: QGlobalStatic<[...]>::operator()() (qglobalstatic.h:128)
      ==16679==    by 0x7F90B8F: QDBusConnection::sessionBus() (qdbusconnection.cpp:1092)
      

      The guilty line of code is

      d = other.d;
      

      in the QDBusConnection copy constructor.

      It is not documented as thread-safe, does this mean that this is not a bug?

      In that case, we do need something like KDE's KDBusConnectionPool in Qt...

      The problem is that there are more races, when using sessionBus() in multiple threads...

      ==16679== Possible data race during read of size 8 at 0xF57F3B8 by thread #2
      ==16679== Locks held: none
      ==16679==    at 0x7F8FEE4: QDBusConnection::registerObject(QString const&, QObject*, QFlags<QDBusConnection::RegisterOption>) (qdbusconnection.cpp:787)
      
      ==16679== This conflicts with a previous write of size 8 by thread #3
      ==16679== Locks held: 1, at address 0x8220A80
      ==16679==    at 0x7FA0215: QDBusConnectionPrivate::setConnection(DBusConnection*, QDBusErrorInternal const&) (qdbusintegrator.cpp:1763)
      ==16679==    by 0x7F8EDAF: QDBusConnection::connectToBus(QDBusConnection::BusType, QString const&) (qdbusconnection.cpp:345)
      

      Attachments

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              dfaure_kdab David Faure
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes