Priority: P2: Important
Affects Version/s: 5.6.0, 5.6.1, 5.8.0, 5.9.0 Alpha
Fix Version/s: 5.9.0 Beta 2
Environment:Windows 7 with MSVC2015 and MinGW 4.9.2
The issue explained below might be an edge case, but is a regression 5.5 -> 5.6.
When loading a dynamic library at runtime with QLibrary and calling a function which initializes QDBusConnectionManager, the application dead locks when trying to unload the library again. The use case for such architecture is plugin libraries, loaded at runtime and using QtDBus connections.
Attached is a small sample reproducing the issue. When running 'app', it loads the library 'lib' and resolves the method 'openDBus'. This method connects to the session bus and disconnects again. After 500 ms, app tries to unload 'lib' again causing the dead lock.
The full stack trace is attached. Snippets are presented below.
Main thread is waiting for QDBusConnectionManager thread to be finished.
however, the QDBusConnectionManager thread is locked with this stack trace:
I have no good idea whats going on and which library is unloaded from the dbus thread. http://stackoverflow.com/questions/10441048/exit-thread-upon-deleting-static-object-during-unload-dll-causes-deadlock explains a very similar thing. LdrUnloadDll is called from both threads, the main one holding the lock and the second one waiting for it. So I suspect something similar is happening here. My first assumption was that libdbus is unloaded from QDBusConnectionManager thread before exiting, however this also happens even if libdbus-1 is not even available. So I have no clue which library is being unloaded in the stack trace.
As soon as the two QDBusConnection calls in lib.cpp are commented, the application quits without issues.
Would a potential solution be to add a shorter timeout to QThread::wait? E.g.