Bug 471941 - KJob dtor force-quits applications
Summary: KJob dtor force-quits applications
Status: RESOLVED NOT A BUG
Alias: None
Product: frameworks-kcoreaddons
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Michael Pyne
URL:
Keywords: qt6
Depends on:
Blocks:
 
Reported: 2023-07-04 13:00 UTC by Harald Sitter
Modified: 2024-03-30 02:39 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
example source (960 bytes, application/x-xz)
2023-07-04 13:00 UTC, Harald Sitter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Sitter 2023-07-04 13:00:52 UTC
Created attachment 160072 [details]
example source

SUMMARY
KJobPrivate has

    // eventLoopLocker prevents QCoreApplication from exiting when the last
    // window is closed until the job has finished running
    QEventLoopLocker eventLoopLocker;

The way this works is that each QEventLoopLocker has a refcount in the QCoreApplication, when the counter hits zero the application quits. That means when all kjobs are destroyed the application always quits - regardless of whether it was meant to!

I'm going to attach a trivial example.

For QGuiApplications this is additionally contingent on its quitOnLastWindowClosed property, but when that is set to false the call chain falls back into QCoreApplication and behaves exactly the same. Put another way: you cannot use KJobs and QGuiApplications that are meant **not** to quit because running out of KJobs always force quits the application.

I'm not quite sure what the fix here should be. Maybe install an eventfilter on the QCoreApplication and only install the lockers on QEvent::Quit? Alternatively we could bounce this to Qt since this behavior arguably makes QEventLoopLocker only niche-useful. Someone probably needs to track whether quit was actually called on the application though.

SOFTWARE/OS VERSIONS
Operating System: KDE neon Unstable Edition
KDE Plasma Version: 5.27.80
KDE Frameworks Version: 5.240.0
Qt Version: 6.5.1
Kernel Version: 5.19.0-42-generic (64-bit)
Graphics Platform: offscreen
Processors: 12 × AMD Ryzen 5 3600X 6-Core Processor
Memory: 31.3 GiB of RAM
Graphics Processor: AMD Radeon RX 5700 XT

ADDITIONAL INFORMATION
Comment 1 Nicolas Fella 2023-07-04 13:34:12 UTC
The fix is to use QCoreApplication::setQuitLockEnabled(false) on the affected apps
Comment 2 Harald Sitter 2023-07-05 06:48:33 UTC
How to inform users of KIO about this?
Comment 3 Nate Graham 2023-07-15 17:32:48 UTC
So Nicolas, is this expected and we need to mention it in the KF5->KF6 porting notes? Or is something we should fix?
Comment 4 Nicolas Fella 2023-07-16 07:36:48 UTC
Strictly speaking this is a pure Qt thing, it just happens to be triggered by KJob.

It's even the case in Qt5 already, the only thing that changed in Qt6 is that setting quitOnLastWindowClosed is not enough to address it any more