Bug 500322

Summary: Crash in KStatusNotifierItemPrivate::~KStatusNotifierItemPrivate during destruction of TrayIcon in 3rd party software
Product: [Frameworks and Libraries] frameworks-kstatusnotifieritem Reporter: gudvinr+kde
Component: generalAssignee: Alexander Lohnau <alexander.lohnau>
Status: REPORTED ---    
Severity: crash CC: nate, oguilherme
Priority: NOR    
Version First Reported In: 6.11.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: gdb stacktrace

Description gudvinr+kde 2025-02-18 15:12:50 UTC
Created attachment 178523 [details]
gdb stacktrace

SUMMARY

proton-bridge (https://github.com/ProtonMail/proton-bridge/) crashes when you close it. Both manually and during system shutdown.

However, they don't use any of KDE stuff. They just use Qt.
And while investigating the issue I found out in core dump that it is crashes inside KDEPlatformSystemTrayIcon::cleanup which is clearly frameworks stuff they very likely don't touch in any way.

See attachment for full trace.

STEPS TO REPRODUCE
1. Launch bridge-gui
2. Quit Bridge

OBSERVED RESULT

Core dump generated.

EXPECTED RESULT

Clean shutdown.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.3.0
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Kernel Version: 6.13.2-arch1-1 (64-bit)
Graphics Platform: X11
Comment 1 gudvinr+kde 2025-02-18 15:15:11 UTC
Interestingly, it looks very similar to 10 years old BUG 343976 and BUG 344799
Comment 2 gudvinr+kde 2025-04-09 17:27:35 UTC
Unfortunately, after updating Qt, Bridge and Frameworks, issue still persists.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 6.3.4
KDE Frameworks Version: 6.12.0
Qt Version: 6.9.0
Kernel Version: 6.14.1-arch1-1 (64-bit)
Graphics Platform: X11
Comment 3 gudvinr+kde 2025-05-07 12:49:09 UTC
Not sure if these are related but Wireshark segfaults inside Breeze::AnimationData::~AnimationData too
Comment 4 Nate Graham 2025-05-20 16:31:48 UTC
Thread 1 (Thread 0x76b4a457db00 (LWP 68836)):
#0  0x000076b4a9b552bb in QCoreApplicationPrivate::deref (this=0x76b4aa1f6ac0 <main_arena>) at /usr/src/debug/qt6-base/qtbase/src/corelib/kernel/qcoreapplication.cpp:2089
#1  QCoreApplicationPrivate::deref (this=0x76b4aa1f6ac0 <main_arena>) at /usr/src/debug/qt6-base/qtbase/src/corelib/kernel/qcoreapplication.cpp:2085
#2  0x000076b4a9b60a31 in operator()<QCoreApplication*> (__closure=<synthetic pointer>, p=<optimized out>) at /usr/src/debug/qt6-base/qtbase/src/corelib/kernel/qeventloop.cpp:424
#3  QEventLoopLocker::visit<QEventLoopLocker::~QEventLoopLocker()::<lambda(auto:40)> > (this=0x596c2f929340, f=...) at /usr/src/debug/qt6-base/qtbase/src/corelib/kernel/qeventloop.cpp:448
#4  QEventLoopLocker::~QEventLoopLocker (this=<optimized out>, this=<optimized out>) at /usr/src/debug/qt6-base/qtbase/src/corelib/kernel/qeventloop.cpp:424
#5  0x000076b4a2daf5b7 in KStatusNotifierItemPrivate::~KStatusNotifierItemPrivate (this=<optimized out>, this=<optimized out>) at /usr/src/debug/kstatusnotifieritem/kstatusnotifieritem-6.11.0/src/kstatusnotifieritemprivate_p.h:94
#6  std::default_delete<KStatusNotifierItemPrivate>::operator() (this=<optimized out>, __ptr=0x596c2f929140) at /usr/include/c++/14.2.1/bits/unique_ptr.h:93
#7  std::default_delete<KStatusNotifierItemPrivate>::operator() (this=<optimized out>, __ptr=0x596c2f929140) at /usr/include/c++/14.2.1/bits/unique_ptr.h:87
#8  std::unique_ptr<KStatusNotifierItemPrivate, std::default_delete<KStatusNotifierItemPrivate> >::~unique_ptr (this=<optimized out>, this=<optimized out>) at /usr/include/c++/14.2.1/bits/unique_ptr.h:399
#9  KStatusNotifierItem::~KStatusNotifierItem (this=<optimized out>, this=<optimized out>) at /usr/src/debug/kstatusnotifieritem/kstatusnotifieritem-6.11.0/src/kstatusnotifieritem.cpp:86
#10 0x000076b4a2daf856 in KStatusNotifierItem::~KStatusNotifierItem (this=<optimized out>, this=<optimized out>) at /usr/src/debug/kstatusnotifieritem/kstatusnotifieritem-6.11.0/src/kstatusnotifieritem.cpp:86
#11 0x000076b4a30b7a9f in KDEPlatformSystemTrayIcon::cleanup (this=0x596c2f954930) at /usr/src/debug/plasma-integration/plasma-integration-6.3.0/qt6/src/platformtheme/kdeplatformsystemtrayicon.cpp:322
#12 0x000076b4abbe3f80 in QSystemTrayIconPrivate::remove_sys (this=0x596c2f94f020) at /usr/src/debug/qt6-base/qtbase/src/widgets/util/qsystemtrayicon_x11.cpp:231
#13 QSystemTrayIcon::~QSystemTrayIcon (this=<optimized out>, this=<optimized out>) at /usr/src/debug/qt6-base/qtbase/src/widgets/util/qsystemtrayicon.cpp:146
#14 0x0000596c166c8073 in TrayIcon::~TrayIcon (this=0x596c2f9280b0, __in_chrg=<optimized out>) at /usr/src/debug/protonmail-bridge/proton-bridge/build/bridge-gui_autogen/EWIEGA46WW/../../../internal/frontend/bridge-gui/bridge-gui/TrayIcon.h:38
#15 TrayIcon::~TrayIcon (this=0x596c2f9280b0, __in_chrg=<optimized out>) at /usr/src/debug/protonmail-bridge/proton-bridge/build/bridge-gui_autogen/EWIEGA46WW/../../../internal/frontend/bridge-gui/bridge-gui/TrayIcon.h:38
#16 std::default_delete<TrayIcon>::operator() (this=<optimized out>, __ptr=0x596c2f9280b0) at /usr/include/c++/14.2.1/bits/unique_ptr.h:93
#17 std::unique_ptr<TrayIcon, std::default_delete<TrayIcon> >::~unique_ptr (this=0x596c2f9387f8, __in_chrg=<optimized out>) at /usr/include/c++/14.2.1/bits/unique_ptr.h:399
#18 QMLBackend::~QMLBackend (this=0x596c2f938780, __in_chrg=<optimized out>) at /usr/src/debug/protonmail-bridge/proton-bridge/build/bridge-gui_autogen/EWIEGA46WW/../../../internal/frontend/bridge-gui/bridge-gui/QMLBackend.h:44
#19 0x0000596c166c886a in QMLBackend::~QMLBackend (this=0x596c2f938780, __in_chrg=<optimized out>) at /usr/src/debug/protonmail-bridge/proton-bridge/internal/frontend/bridge-gui/bridge-gui/QMLBackend.h:44
#20 std::default_delete<QMLBackend>::operator() (this=<optimized out>, __ptr=0x596c2f938780) at /usr/include/c++/14.2.1/bits/unique_ptr.h:93
#21 std::unique_ptr<QMLBackend, std::default_delete<QMLBackend> >::~unique_ptr (this=0x596c169aac30 <app()::app+16>, __in_chrg=<optimized out>) at /usr/include/c++/14.2.1/bits/unique_ptr.h:399
#22 AppController::~AppController (this=0x596c169aac20 <app()::app>, __in_chrg=<optimized out>) at /usr/src/debug/protonmail-bridge/proton-bridge/internal/frontend/bridge-gui/bridge-gui/AppController.cpp:63
#23 0x000076b4aa04e391 in __run_exit_handlers (status=0, listp=0x76b4aa1f6680 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:118
#24 0x000076b4aa04e46e in __GI_exit (status=<optimized out>) at exit.c:148
#25 0x000076b4aa03548f in __libc_start_call_main (main=main@entry=0x596c166bbbc0 <main(int, char**)>, argc=argc@entry=1, argv=argv@entry=0x7ffe5676fa28) at ../sysdeps/nptl/libc_start_call_main.h:74
#26 0x000076b4aa03554c in __libc_start_main_impl (main=0x596c166bbbc0 <main(int, char**)>, argc=1, argv=0x7ffe5676fa28, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffe5676fa18) at ../csu/libc-start.c:360
#27 0x0000596c166bdd05 in _start ()
Comment 5 John Kizer 2025-05-26 04:54:39 UTC
*** Bug 500563 has been marked as a duplicate of this bug. ***
Comment 6 Guilherme Silva 2025-06-22 17:33:11 UTC
I was getting a bit tired of seeing Proton Mail Bridge crash every time when exiting, so I asked ChatGPT for help analyzing the gdb backtrace, due to my incompetence with C++/Qt.

To keep things short, ChatGPT determined that the culprit of the crash is Proton Mail Bridge itself. Though I still don't understand why it doesn't crash under a COSMIC session, as I reported in https://bugs.kde.org/show_bug.cgi?id=500563.

Anyway, after a little back and forth, ChatGPT suggested me to add this code in Proton Mail Bridge's QMLBackend::init() [1]:

// make sure the tray icon is destroyed before QApplication dtor
connect(qApp, &QCoreApplication::aboutToQuit, this, [this] {
    trayIcon_.reset();
});

So I added that after line 67, rebuilt and repackeged the Proton Mail Bridge, and sure enough, it stopped crashing after exiting!

I'd send a pull request to Proton Mail Bridge, but I don't feel confident enough to send PRs for stuff I didn't come up myself. But if anyone reading this wants to do that, please go ahead.

It'd be great if KStatusNotifierItem could prevent this crash somehow, but I have no clue if that's even possible.

[1] https://github.com/ProtonMail/proton-bridge/blob/e9ea976773c7d78866c32bd5bce669400283bdc0/internal/frontend/bridge-gui/bridge-gui/QMLBackend.cpp#L62