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

Deadlock in QGuiApplication's destructor

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.12.6
    • Core: Threads, GUI: Other
    • None
    • Linux/X11

    Description

      Hello,

      Sometimes, the destructor of QGuiApplication is blocked on a pthread_join so the main program is never finished.

      The consequences are that we need to send SIGKILL or something like this to be able to close Application process. The UI is well became invisible but the application is still running.

      I have a GUI application that use QML for Views and C++ for ViewModels and Models, I also have 2 different WebEngineView that instantiate JS Web App.

      Here is my main.cpp:

      //main.cpp
      int main(int argc, char* argv[]){  
      
      qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-in-process-stack-traces"); 
      QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);        QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
      auto qApplication = make_shared<QGuiApplication>(argc, argv);        QtWebEngine::initialize();
      ...
      auto qmlApplicationEngine = make_unique<QQmlApplicationEngine>();
      auto program = make_shared<Program>(qApplication);
      qmlApplicationEngine->load(QUrl("qrc:/main/qml/main.qml"));
      
      auto retCode = qApplication->exec();
      
      program->Cleanup();
              
      qmlApplicationEngine = nullptr;
      program = nullptr;
      
      return retCode;
      
      }

      Here is how I try to exit the QGuiApplication :

      //Program.cpp
      void Program::Exit(){    
      
      _exiting = true;    
      auto exitCode = static_cast<int>(ExitCode::Quit);
      LOG_INFO(LoggingManager::GetLoggerPtr("Program"), "Exit with exitCode: " << exitCode);
      Cleanup();    
      qApp->exit(exitCode);
      
      }
      
      //Window.qml
      ApplicationWindow {
      ...
       onClosing: {   
          close.accepted = false;
          program.Exit();  
       }
      }

      When I launch my Application in debug and issue occurs, I can see that main is executing the destructor of QGuiApplication and this object wait on a particular thread because I can see in stack trace the usage of pthread_join() function. 

      Here is a screenshot of stack trace of main thread that execute QGuiApplication destructor :

      When reading docs, I know that QGuiApplication wait for end of QThreads that it has created. So I check for other QThreads that are always running and I see 3 threads : One that uses QDBusConnectionManager::run(), one that uses QXcbEventQueue::run(), and one that seems doing nothing ...

      Here is a screenshot of stack trace for QThread that seems doing nothing:

      In my Application, I'm not creating explicitly a QThread so I think this thread is created by QT himself.

      This kind of issue is quite annoying because double clicking on App doesn't launch another Application if an instance is already running. So user has to restart machine or kill by hand the Application process (not user-friendly).

       

      Do you have an idea of why this QThread is created and why it blocks QGuiApplication in his destructor ?

       

      Thanks in advance

      Attachments

        1. image-2023-02-22-16-47-04-727.png
          62 kB
          Loic Peters
        2. image-2023-02-22-16-53-56-181.png
          38 kB
          Loic Peters

        Activity

          People

            thiago Thiago Macieira
            azrod-afk Loic Peters
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: