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

Bearer plugins can get unloaded while the bearer thread is still running

    XMLWordPrintable

Details

    Description

      See the attached backtrace, for which this applies:

      (gdb) info threads
        Id   Target Id         Frame 
        1    Thread 0x7ffff7fa8400 (LWP 31057) "python3" 0x00007ffff76fc10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
        2    Thread 0x7fffd3afa700 (LWP 32611) "QXcbEventReader" 0x00007ffff743048d in poll () from /usr/lib/libc.so.6
        3    Thread 0x7fffcb9a3700 (LWP 32625) "python3" 0x00007ffff76fc10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
      * 5    Thread 0x7fff8a68f700 (LWP 32627) "QDBusConnection" 0x00007ffff585c9cf in QObject::disconnect (sender=0x7fff801b6320, signal=signal@entry=0x0, receiver=receiver@entry=0x7fff7c008130, method=method@entry=0x0)
          at kernel/qobject.cpp:2956
        6    Thread 0x7fff89e8e700 (LWP 32628) "Qt bearer threa" 0x00007ffff743048d in poll () from /usr/lib/libc.so.6
        7    Thread 0x7fff8892a700 (LWP 32630) "python3" 0x00007ffff76fc10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
        8    Thread 0x7fff7bfff700 (LWP 32631) "python3" 0x00007ffff76fc10f in pthread_cond_wait@@GLIBC_2.3.2 () from /usr/lib/libpthread.so.0
      

      Note that the "Qt bearer thread" (thread 6) is still running. Investigation in QTBUG-52988 shows that the crash is caused by the plugins having already been unloaded.

      This is possible if QApplication has not yet been destroyed by the time exit() starts (possible leak), as the bearer thread is stopped by a qAddPostRoutine. But the plugins themselves are loaded by a static QFactoryLoader in QNetworkConfigurationManagerPrivate::updateConfigurations(), which must have already got destroyed.

      To reproduce:

      • apply the following patch to examples/network/bearermonitor
        --- examples/network/bearermonitor/main.cpp
        +++ examples/network/bearermonitor/main.cpp
        @@ -50,12 +50,14 @@
         
         #include <QtWidgets/QApplication>
         #include <QtWidgets/QMainWindow>
        +#include <QtDBus/QtDBus>
         
         #include "bearermonitor.h"
         
         int main(int argc, char *argv[])
         {
        -    QApplication app(argc, argv);
        +    auto app = new QApplication(argc, argv);
        +    QDBusConnection::sessionBus();
         
             QMainWindow mainWindow;
         
        @@ -64,6 +66,6 @@ int main(int argc, char *argv[])
             mainWindow.setCentralWidget(&monitor);
             mainWindow.show();
         
        -    return app.exec();
        +    return app->exec();
         }
         
        --- examples/network/bearermonitor/bearermonitor.pro
        +++ examples/network/bearermonitor/bearermonitor.pro
        @@ -1,5 +1,5 @@
         TARGET = bearermonitor
        -QT = core gui network widgets
        +QT = core gui network widgets dbus
         
         HEADERS = sessionwidget.h \
                   bearermonitor.h
        

      Note: the crash does not affect Qt 5.7 due to QFactoryLoader no longer unloading its plugins (commit 494376f980e96339b6f1eff7c41336ca4d853065).

      Attachments

        Issue Links

          Activity

            People

              thiago Thiago Macieira
              thiago Thiago Macieira
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: