Bug 465326

Summary: While handling an image in klipper history, Plasma freezes for a some time with 100% CPU usage then crashes
Product: [Plasma] plasmashell Reporter: Oded Arbel <oded>
Component: ClipboardAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED DUPLICATE    
Severity: crash CC: kde, nate, oshiorns1+kdebugs, qydwhotmail
Priority: VHI Keywords: drkonqi
Version: master   
Target Milestone: 1.0   
Platform: Neon   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=465225
https://bugs.kde.org/show_bug.cgi?id=464828
https://bugs.kde.org/show_bug.cgi?id=465603
Latest Commit: Version Fixed In: 5.27
Sentry Crash Report:
Attachments: New crash information added by DrKonqi

Description Oded Arbel 2023-02-05 17:46:11 UTC
Application: plasmashell (5.27.80)

Qt Version: 5.15.8
Frameworks Version: 5.103.0
Operating System: Linux 5.19.0-29-generic x86_64
Windowing System: Wayland
Distribution: KDE neon Unstable Edition
DrKonqi: 5.27.80 [CoredumpBackend]

-- Information about the crash:
After today's update of plasma-shell from Neon unstable, Plasma occaisonally crashes when trying to open the Kickoff menu: If I press the super key, instead of opening the menu, the shell freezes (panel is unresponsive and wallpaper grays out) and after a few seconds the plasmashell UI is gone and then restarts.

After that was happening a few times, currently its working fine 🀷

The crash can be reproduced sometimes.

-- Backtrace (Reduced):
#6  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#7  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#8  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#9  0x00007fe920a3bc46 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#10 0x00007fe920a227fc in __GI_abort () at ./stdlib/abort.c:79


Reported using DrKonqi
Comment 1 Oded Arbel 2023-02-05 17:46:12 UTC
Created attachment 155969 [details]
New crash information added by DrKonqi

DrKonqi auto-attaching complete backtrace.
Comment 2 Oded Arbel 2023-02-05 17:58:41 UTC
It also happens spontaneously and quite often - it doesn't look to actually have anything to do with opening the menu, and appear to be related to activities: plasmashell now freezes when I try to switch activities, either by using the "next activity" global shortcut, or when trying to open the activity switcher UI. When it crashes I get the same backtrace (reproduced here):


Thread 1 (Thread 0x7fcbe96ff6c0 (LWP 1256949)):
[KCrash Handler]
#6  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#7  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#8  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#9  0x00007fccb4e3bc46 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#10 0x00007fccb4e227fc in __GI_abort () at ./stdlib/abort.c:79
#11 0x00007fccb52a2b9e in __gnu_cxx::__verbose_terminate_handler() () at ../../../../src/libstdc++-v3/libsupc++/vterminate.cc:95
#12 0x00007fccb52ae34c in __cxxabiv1::__terminate(void (*)()) (handler=<optimized out>) at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:48
#13 0x00007fccb52ae3b7 in std::terminate() () at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:58
#14 0x00007fccb5690f91 in qTerminate() () at global/qglobal.cpp:3382
#15 0x00007fccb5692e3c in QThreadPrivate::start(void*) (arg=0x55f26e7adc80) at thread/qthread_unix.cpp:342
#16 0x00007fccb4e90402 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#17 0x00007fccb4f1f590 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
Comment 3 Oded Arbel 2023-02-05 19:00:43 UTC
Also, whenever plasmashell crashes, it takes with it some - but not all - of my running applications: notably, Eclipse, Slack and Google Chrome, but not Firefox, Konsole or Discover.
Comment 4 Nate Graham 2023-02-07 00:54:47 UTC
What kernel version do you have? With 6.1.7 I was getting a lot of hangs in statx() system calls. with 6.1.8, it seems to be fixed.

It would be very helpful if you could get a backtrace of the hang when it happens, if you can either launch Konsole or if it was already running and didn't hang. You would enter these commands:

$ gdb attach $(pidof plasmashell)
$ bt

And if not, you an do that in a virtual terminal.
Comment 5 Oded Arbel 2023-02-07 06:38:02 UTC
(In reply to Nate Graham from comment #4)
> What kernel version do you have?

I'm still running on 5.19.0.

> It would be very helpful if you could get a backtrace of the hang when it
> happens

The freeze is pretty short, but I'll try - I wrote a script to automate that, hopefully I can trigger it in time.

What I find interesting is that the crash backtrace shows the crashing thread is "thread 1", but obviously it wasn't the main thread (it starts with a clone, i.e. it was created as a thread).
Comment 6 Oded Arbel 2023-02-07 10:12:58 UTC
The current behavior (after all today's updates) is that the crash happens frequently while I'm doing other things, regardless of interaction with the shell itself, so its hard for me to catch it. But the shell does freeze quite a lot - at which point plasmashell uses 100% of a core - and if I capture the backtrace while it happens, the main thread looks like this:

Thread 1 (Thread 0x7f108992f9c0 (LWP 36226) "plasmashell"):
#0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1  0x00007f108dccea65 in QtLinuxFutex::_q_futex(int*, int, int, unsigned long long, int*, int) (val3=0, addr2=0x0, val2=0, val=3, op=0, addr=0x560684982d48) at thread/qfutex_p.h:114
#2  QtLinuxFutex::futexWait<QBasicAtomicPointer<QMutexData> >(QBasicAtomicPointer<QMutexData>&, QBasicAtomicPointer<QMutexData>::Type) (expectedValue=0x3, futex=...) at thread/qfutex_p.h:133
#3  lockInternal_helper<false> (timeout=-1, elapsedTimer=0x0, d_ptr=...) at thread/qmutex_linux.cpp:142
#4  QBasicMutex::lockInternal() (this=0x560684982d48) at thread/qmutex_linux.cpp:159
#5  0x00007f108dcced73 in QBasicMutex::lock() (this=0x560684982d48) at thread/qmutex.h:84
#6  QRecursiveMutexPrivate::lock(int) (this=0x560684982d30, timeout=timeout@entry=-1) at thread/qmutex.cpp:780
#7  0x00007f108dccec69 in QMutex::lock() (this=this@entry=0x560684983270) at thread/qmutex.cpp:235
#8  0x00007f10041ef100 in QMutexLocker::QMutexLocker(QBasicMutex*) (m=0x560684983270, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:257
#9  QMutexLocker::QMutexLocker(QRecursiveMutex*) (m=0x560684983270, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:262
#10 HistoryModel::insert(std::shared_ptr<HistoryItem>) (this=0x560684983250, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/historymodel.cpp:135
#11 0x00007f10041ea0d2 in History::insert(std::shared_ptr<HistoryItem>) (this=<optimized out>, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/history.cpp:95
#12 0x00007f10041d4166 in Klipper::applyClipChanges(QMimeData const*) (this=this@entry=0x5606836c9840, clipData=clipData@entry=0x560688d5a8f0) at ./klipper/klipper.cpp:687
#13 0x00007f10041d6a48 in Klipper::checkClipData(bool) (this=0x5606836c9840, selectionMode=<optimized out>) at ./klipper/klipper.cpp:828
#14 0x00007f108def40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffc7a38d1e0, r=0x5606836c9840, this=0x560684982f70) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#15 doActivate<false>(QObject*, int, void**) (sender=0x560684983020, signal_index=3, argv=0x7ffc7a38d1e0) at kernel/qobject.cpp:3923
#16 0x00007f108d6230a2 in KSystemClipboard::changed(QClipboard::Mode) () at /lib/x86_64-linux-gnu/libKF5GuiAddons.so.5
#17 0x00007f108def40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffc7a38d290, r=0x560684983020, this=0x560684977590) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#18 doActivate<false>(QObject*, int, void**) (sender=0x560682375de0, signal_index=3, argv=0x7ffc7a38d290) at kernel/qobject.cpp:3923
#19 0x00007f108f8a2e2e in ffi_call_unix64 () at ../src/x86/unix64.S:105
#20 0x00007f108f89f493 in ffi_call_int (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>, avalue=<optimized out>, closure=<optimized out>) at ../src/x86/ffi64.c:672
#21 0x00007f1090451b20 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#22 0x00007f10904522c3 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#23 0x00007f10904524bc in wl_display_dispatch_queue_pending () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#24 0x00007f108f92338a in QtWaylandClient::QWaylandDisplay::flushRequests() (this=<optimized out>) at ./src/client/qwaylanddisplay.cpp:253
#25 0x00007f108dee9ade in QObject::event(QEvent*) (this=0x56068235bb50, e=0x7f107c013b70) at kernel/qobject.cpp:1347
#26 0x00007f108ed6c793 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x56068235bb50, e=0x7f107c013b70) at kernel/qapplication.cpp:3640
#27 0x00007f108debc07a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x56068235bb50, event=0x7f107c013b70) at kernel/qcoreapplication.cpp:1064
#28 0x00007f108debf167 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (receiver=0x0, event_type=0, data=0x560682332ec0) at kernel/qcoreapplication.cpp:1821
#29 0x00007f108df16487 in postEventSourceDispatch(GSource*, GSourceFunc, gpointer) (s=0x560682374cc0) at kernel/qeventdispatcher_glib.cpp:277
#30 0x00007f108cb5d569 in g_main_dispatch (context=0x7f1084005010) at ../../../glib/gmain.c:3444
#31 g_main_context_dispatch (context=0x7f1084005010) at ../../../glib/gmain.c:4162
#32 0x00007f108cbb23c8 in g_main_context_iterate.constprop.0 (context=0x7f1084005010, block=<optimized out>, dispatch=1, self=<optimized out>) at ../../../glib/gmain.c:4238
#33 0x00007f108cb5ad20 in g_main_context_iteration (context=0x7f1084005010, may_block=1) at ../../../glib/gmain.c:4303
#34 0x00007f108df15ad8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x560682387240, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#35 0x00007f108deba99b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7ffc7a38da50, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#36 0x00007f108dec2f34 in QCoreApplication::exec() () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#37 0x00007f108e3364d0 in QGuiApplication::exec() () at kernel/qguiapplication.cpp:1870
#38 0x00007f108ed6c709 in QApplication::exec() () at kernel/qapplication.cpp:2832
#39 0x0000560681cb0a8b in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ./shell/main.cpp:235

I also figured out why it takes out my apps - I'm using the systemd service and I can see that *some* processes launched from the plasma main menu - notably Eclipse and Chrome - are running in the systemd service's scope instead of their own app scope, so when the service restarts after the main process crashes, it kills all the other processes in the scope.

Weirdly, it looks like Plasma does try to run each app in its own scope, but... for some apps it doesn't work (??)... systemd-cgls shows this weird setup:

─plasma-plasmashell.service (#17260)
 β”œβ”€38246 /usr/bin/plasmashell --no-respawn
 β”œβ”€38282 /lib/x86_64-linux-gnu/libexec/kf5/kioslave5 /usr/lib/x86_64-linux-gnu/qt5/plugins/kf5/kio/desktop.so desktop  local:/run/user/1000/plasmashelleVuhbK.1.kioworker.socket
 β”œβ”€38374 /lib/x86_64-linux-gnu/libexec/kf5/kioslave5 /usr/lib/x86_64-linux-gnu/qt5/plugins/kf5/kio/tags.so tags  local:/run/user/1000/plasmashellPtEzPm.2.kioworker.socket
 β”œβ”€38633 /home/odeda/.local/eclipse/eclipse-2022-06-R/eclipse
 β”œβ”€38655 /home/odeda/.local/eclipse/eclipse-2022-06-R//plugins/org.eclipse.justj.openjdk.hotspot.jre.full.linux.x86_64_18.0.1.v20220515-1614/jre/bin/java --add-opens=java.base/java.io=ALL-UNN>
 β”œβ”€38769 /opt/google/chrome/chrome
...
─app-google\x2dchrome\x2dwork-10fad962c3fb471d93221f0a97b25e63.scope (#17498)
 └─38768 /bin/sh -c google-chrome
...
─app-Eclipse-913daf03aafb4e75abc14a51942f13d4.scope (#17461)
 └─38632 /bin/sh -c /usr/bin/env GDK_BACKEND=x11 $HOME/.local/eclipse/eclipse-2022-06-R/eclipse
Comment 7 Oded Arbel 2023-02-08 19:12:24 UTC
This crash still happens after tonight's neon unstable updates. I think it is definitely related to klipper's HistoryModel::insert() operation: something in the mutex there is causing an issue - if we look at the last (first?) 2 threads from the stack trace (appended here is a new one from just about now), we can see that "Thread 1" (LWP 585125) is not the main thread (like it is in most back traces), its just a thread that was created to invoke qTerminate(), while the main thread is "Thread 2"  (which has the earlier LWP id 550212) - and that one is blocking in HistoryModel::insert(). This is also where plasmashell gets stuck when it freezes on me - like it is right now, and then it crashed. Maybe it is some kind of watchdog?

I tried to look at what could be deadlocking with the HistoryModel::insert() mutex but (a) when backtracing a frozen plasmashell, I don't see anything else holding a QMutexLocker, and (b) looking at the source code I can see that HistoryModel exposes a pointer to its mutex using a public accessor, so anyone can be locking it 🀷🀦.

Here's the last 2 threads from the (one of) the new crash:

Thread 2 (Thread 0x7fbc546629c0 (LWP 550212)):
#0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1  0x00007fbc56ecea65 in QtLinuxFutex::_q_futex(int*, int, int, unsigned long long, int*, int) (val3=0, addr2=0x0, val2=0, val=3, op=0, addr=0x564becec7268) at thread/qfutex_p.h:114
#2  QtLinuxFutex::futexWait<QBasicAtomicPointer<QMutexData> >(QBasicAtomicPointer<QMutexData>&, QBasicAtomicPointer<QMutexData>::Type) (expectedValue=0x3, futex=...) at thread/qfutex_p.h:133
#3  lockInternal_helper<false> (timeout=-1, elapsedTimer=0x0, d_ptr=...) at thread/qmutex_linux.cpp:142
#4  QBasicMutex::lockInternal() (this=0x564becec7268) at thread/qmutex_linux.cpp:159
#5  0x00007fbc56eced73 in QBasicMutex::lock() (this=0x564becec7268) at thread/qmutex.h:84
#6  QRecursiveMutexPrivate::lock(int) (this=0x564becec7250, timeout=timeout@entry=-1) at thread/qmutex.cpp:780
#7  0x00007fbc56ecec69 in QMutex::lock() (this=this@entry=0x564becec6fd0) at thread/qmutex.cpp:235
#8  0x00007fbbec059100 in QMutexLocker::QMutexLocker(QBasicMutex*) (m=0x564becec6fd0, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:257
#9  QMutexLocker::QMutexLocker(QRecursiveMutex*) (m=0x564becec6fd0, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:262
#10 HistoryModel::insert(std::shared_ptr<HistoryItem>) (this=0x564becec6fb0, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/historymodel.cpp:135
#11 0x00007fbbec0540d2 in History::insert(std::shared_ptr<HistoryItem>) (this=<optimized out>, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/history.cpp:95
#12 0x00007fbbec03e166 in Klipper::applyClipChanges(QMimeData const*) (this=this@entry=0x564bec263290, clipData=clipData@entry=0x564bf149c600) at ./klipper/klipper.cpp:687
#13 0x00007fbbec040a48 in Klipper::checkClipData(bool) (this=0x564bec263290, selectionMode=<optimized out>) at ./klipper/klipper.cpp:828
#14 0x00007fbc570f40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7fffd0088e60, r=0x564bec263290, this=0x564becec6ad0) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#15 doActivate<false>(QObject*, int, void**) (sender=0x564becec72b0, signal_index=3, argv=0x7fffd0088e60) at kernel/qobject.cpp:3923
#16 0x00007fbc5650d0a2 in KSystemClipboard::changed(QClipboard::Mode) () at /lib/x86_64-linux-gnu/libKF5GuiAddons.so.5
#17 0x00007fbc570f40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7fffd0088f10, r=0x564becec72b0, this=0x564becebf980) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#18 doActivate<false>(QObject*, int, void**) (sender=0x564beaa64de0, signal_index=3, argv=0x7fffd0088f10) at kernel/qobject.cpp:3923
#19 0x00007fbc58aa9e2e in ffi_call_unix64 () at ../src/x86/unix64.S:105
#20 0x00007fbc58aa6493 in ffi_call_int (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>, avalue=<optimized out>, closure=<optimized out>) at ../src/x86/ffi64.c:672
#21 0x00007fbc59561b20 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#22 0x00007fbc595622c3 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#23 0x00007fbc595624bc in wl_display_dispatch_queue_pending () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#24 0x00007fbc5852338a in QtWaylandClient::QWaylandDisplay::flushRequests() (this=<optimized out>) at ./src/client/qwaylanddisplay.cpp:253
#25 0x00007fbc570e9ade in QObject::event(QEvent*) (this=0x564beaa4ab50, e=0x7fbc48008100) at kernel/qobject.cpp:1347
#26 0x00007fbc57d6c793 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x564beaa4ab50, e=0x7fbc48008100) at kernel/qapplication.cpp:3640
#27 0x00007fbc570bc07a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x564beaa4ab50, event=0x7fbc48008100) at kernel/qcoreapplication.cpp:1064
#28 0x00007fbc570bf167 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (receiver=0x0, event_type=0, data=0x564beaa21ec0) at kernel/qcoreapplication.cpp:1821
#29 0x00007fbc57116487 in postEventSourceDispatch(GSource*, GSourceFunc, gpointer) (s=0x564beaa63cc0) at kernel/qeventdispatcher_glib.cpp:277
#30 0x00007fbc55c95569 in g_main_dispatch (context=0x7fbc4c005010) at ../../../glib/gmain.c:3444
#31 g_main_context_dispatch (context=0x7fbc4c005010) at ../../../glib/gmain.c:4162
#32 0x00007fbc55cea3c8 in g_main_context_iterate.constprop.0 (context=0x7fbc4c005010, block=<optimized out>, dispatch=1, self=<optimized out>) at ../../../glib/gmain.c:4238
#33 0x00007fbc55c92d20 in g_main_context_iteration (context=0x7fbc4c005010, may_block=1) at ../../../glib/gmain.c:4303
#34 0x00007fbc57115ad8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x564beaa76140, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#35 0x00007fbc570ba99b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7fffd00896d0, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#36 0x00007fbc570c2f34 in QCoreApplication::exec() () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#37 0x00007fbc575364d0 in QGuiApplication::exec() () at kernel/qguiapplication.cpp:1870
#38 0x00007fbc57d6c709 in QApplication::exec() () at kernel/qapplication.cpp:2832
#39 0x0000564bea819a8b in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ./shell/main.cpp:235

Thread 1 (Thread 0x7fbb8deff6c0 (LWP 585125)):
[KCrash Handler]
#6  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#7  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#8  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#9  0x00007fbc5663bc46 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#10 0x00007fbc566227fc in __GI_abort () at ./stdlib/abort.c:79
#11 0x00007fbc56aa2b9e in __gnu_cxx::__verbose_terminate_handler() () at ../../../../src/libstdc++-v3/libsupc++/vterminate.cc:95
#12 0x00007fbc56aae34c in __cxxabiv1::__terminate(void (*)()) (handler=<optimized out>) at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:48
#13 0x00007fbc56aae3b7 in std::terminate() () at ../../../../src/libstdc++-v3/libsupc++/eh_terminate.cc:58
#14 0x00007fbc56e90f91 in qTerminate() () at global/qglobal.cpp:3382
#15 0x00007fbc56e92e3c in QThreadPrivate::start(void*) (arg=0x7fbbf8005190) at thread/qthread_unix.cpp:342
#16 0x00007fbc56690402 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#17 0x00007fbc5671f590 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

And here's "Thread 1" from backtracing plasmashell when it freezes on me:

Thread 1 (Thread 0x7fe1c4d3d9c0 (LWP 601294) "plasmashell"):
#0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1  0x00007fe1c90cea65 in QtLinuxFutex::_q_futex(int*, int, int, unsigned long long, int*, int) (val3=0, addr2=0x0, val2=0, val=3, op=0, addr=0x56218cefa708) at thread/qfutex_p.h:114
#2  QtLinuxFutex::futexWait<QBasicAtomicPointer<QMutexData> >(QBasicAtomicPointer<QMutexData>&, QBasicAtomicPointer<QMutexData>::Type) (expectedValue=0x3, futex=...) at thread/qfutex_p.h:133
#3  lockInternal_helper<false> (timeout=-1, elapsedTimer=0x0, d_ptr=...) at thread/qmutex_linux.cpp:142
#4  QBasicMutex::lockInternal() (this=0x56218cefa708) at thread/qmutex_linux.cpp:159
#5  0x00007fe1c90ced73 in QBasicMutex::lock() (this=0x56218cefa708) at thread/qmutex.h:84
#6  QRecursiveMutexPrivate::lock(int) (this=0x56218cefa6f0, timeout=timeout@entry=-1) at thread/qmutex.cpp:780
#7  0x00007fe1c90cec69 in QMutex::lock() (this=this@entry=0x56218cefaad0) at thread/qmutex.cpp:235
#8  0x00007fe157f41100 in QMutexLocker::QMutexLocker(QBasicMutex*) (m=0x56218cefaad0, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:257
#9  QMutexLocker::QMutexLocker(QRecursiveMutex*) (m=0x56218cefaad0, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:262
#10 HistoryModel::insert(std::shared_ptr<HistoryItem>) (this=0x56218cefaab0, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/historymodel.cpp:135
#11 0x00007fe157f3c0d2 in History::insert(std::shared_ptr<HistoryItem>) (this=<optimized out>, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/history.cpp:95
#12 0x00007fe157f26166 in Klipper::applyClipChanges(QMimeData const*) (this=this@entry=0x56218c3e1ab0, clipData=clipData@entry=0x5621931befa0) at ./klipper/klipper.cpp:687
#13 0x00007fe157f28a48 in Klipper::checkClipData(bool) (this=0x56218c3e1ab0, selectionMode=<optimized out>) at ./klipper/klipper.cpp:828
#14 0x00007fe1c92f40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffe977ce270, r=0x56218c3e1ab0, this=0x56218cefa590) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#15 doActivate<false>(QObject*, int, void**) (sender=0x56218cef6ec0, signal_index=3, argv=0x7ffe977ce270) at kernel/qobject.cpp:3923
#16 0x00007fe1c8a230a2 in KSystemClipboard::changed(QClipboard::Mode) () at /lib/x86_64-linux-gnu/libKF5GuiAddons.so.5
#17 0x00007fe1c92f40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffe977ce320, r=0x56218cef6ec0, this=0x56218ceeb740) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#18 doActivate<false>(QObject*, int, void**) (sender=0x56218adc8e00, signal_index=3, argv=0x7ffe977ce320) at kernel/qobject.cpp:3923
#19 0x00007fe1cb393e2e in ffi_call_unix64 () at ../src/x86/unix64.S:105
#20 0x00007fe1cb390493 in ffi_call_int (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>, avalue=<optimized out>, closure=<optimized out>) at ../src/x86/ffi64.c:672
#21 0x00007fe1cb860b20 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#22 0x00007fe1cb8612c3 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#23 0x00007fe1cb8614bc in wl_display_dispatch_queue_pending () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#24 0x00007fe1cad2338a in QtWaylandClient::QWaylandDisplay::flushRequests() (this=<optimized out>) at ./src/client/qwaylanddisplay.cpp:253
#25 0x00007fe1c92e9ade in QObject::event(QEvent*) (this=0x56218adaeb50, e=0x7fe1b4006ba0) at kernel/qobject.cpp:1347
#26 0x00007fe1ca16c793 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x56218adaeb50, e=0x7fe1b4006ba0) at kernel/qapplication.cpp:3640
#27 0x00007fe1c92bc07a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x56218adaeb50, event=0x7fe1b4006ba0) at kernel/qcoreapplication.cpp:1064
#28 0x00007fe1c92bf167 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (receiver=0x0, event_type=0, data=0x56218ad85ec0) at kernel/qcoreapplication.cpp:1821
#29 0x00007fe1c9316487 in postEventSourceDispatch(GSource*, GSourceFunc, gpointer) (s=0x56218adc7ce0) at kernel/qeventdispatcher_glib.cpp:277
#30 0x00007fe1c7f85569 in g_main_dispatch (context=0x7fe1bc005010) at ../../../glib/gmain.c:3444
#31 g_main_context_dispatch (context=0x7fe1bc005010) at ../../../glib/gmain.c:4162
#32 0x00007fe1c7fda3c8 in g_main_context_iterate.constprop.0 (context=0x7fe1bc005010, block=<optimized out>, dispatch=1, self=<optimized out>) at ../../../glib/gmain.c:4238
#33 0x00007fe1c7f82d20 in g_main_context_iteration (context=0x7fe1bc005010, may_block=1) at ../../../glib/gmain.c:4303
#34 0x00007fe1c9315ad8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x56218adda3c0, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#35 0x00007fe1c92ba99b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7ffe977ceae0, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#36 0x00007fe1c92c2f34 in QCoreApplication::exec() () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#37 0x00007fe1c97364d0 in QGuiApplication::exec() () at kernel/qguiapplication.cpp:1870
#38 0x00007fe1ca16c709 in QApplication::exec() () at kernel/qapplication.cpp:2832
#39 0x0000562189027a8b in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ./shell/main.cpp:235
Comment 8 Oded Arbel 2023-02-09 11:06:45 UTC
Huh, apparently I needed to look at the logs:

---8<---
Feb 09 12:42:03 vesho plasmashell[871706]: QBuffer::writeData: Memory allocation error
Feb 09 12:42:03 vesho plasmashell[871706]: libpng error: Write Error
# the above two lines repeat many times...
Feb 09 12:42:03 vesho plasmashell[871706]: QBuffer::writeData: Memory allocation error
Feb 09 12:42:03 vesho plasmashell[871706]: libpng error: Write Error
Feb 09 12:42:03 vesho plasmashell[871706]: Qt Concurrent has caught an exception thrown from a worker thread.
                                           This is not supported, exceptions thrown in worker threads must be
                                           caught before control returns to Qt Concurrent.
Feb 09 12:42:03 vesho plasmashell[871706]: terminate called after throwing an instance of 'std::bad_alloc'
Feb 09 12:42:03 vesho plasmashell[871706]:   what():  std::bad_alloc
Feb 09 12:42:03 vesho plasmashell[871706]: 25 -- exe=/usr/bin/plasmashell
Feb 09 12:42:03 vesho plasmashell[871706]: 17 -- platform=wayland
Feb 09 12:42:03 vesho plasmashell[871706]: 20 -- appname=plasmashell
Feb 09 12:42:03 vesho plasmashell[871706]: 17 -- apppath=/usr/bin
Feb 09 12:42:03 vesho plasmashell[871706]: 9 -- signal=6
Feb 09 12:42:03 vesho plasmashell[871706]: 11 -- pid=871706
Feb 09 12:42:03 vesho plasmashell[871706]: 19 -- appversion=5.27.80
Feb 09 12:42:03 vesho plasmashell[871706]: 19 -- programname=Plasma
Feb 09 12:42:03 vesho plasmashell[871706]: 31 -- bugaddress=submit@bugs.kde.org
---8<---
Comment 9 Oded Arbel 2023-02-09 11:47:03 UTC
I believe the issue is that klipper is having a real hard time managing images in the clipboard history (I had to screenshot followed by copy and paste a lot last week), to the point of crashing plasmashell (which begs the question, BTW, why is it running on plasmashell's main thread - it used to be a standalone application). I tried to clear the clipboard history using the clipboard panel widget's "clear" button, after which plasmashell froze for some minutes (!!) with this trace:

---8<---
Thread 1 (Thread 0x7f86339a19c0 (LWP 885456) "plasmashell"):
#0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1  0x00007f8637ecea65 in QtLinuxFutex::_q_futex(int*, int, int, unsigned long long, int*, int) (val3=0, addr2=0x0, val2=0, val=3, op=0, addr=0x5601db2ee2f8) at thread/qfutex_p.h:114
#2  QtLinuxFutex::futexWait<QBasicAtomicPointer<QMutexData> >(QBasicAtomicPointer<QMutexData>&, QBasicAtomicPointer<QMutexData>::Type) (expectedValue=0x3, futex=...) at thread/qfutex_p.h:133
#3  lockInternal_helper<false> (timeout=-1, elapsedTimer=0x0, d_ptr=...) at thread/qmutex_linux.cpp:142
#4  QBasicMutex::lockInternal() (this=0x5601db2ee2f8) at thread/qmutex_linux.cpp:159
#5  0x00007f8637eced73 in QBasicMutex::lock() (this=0x5601db2ee2f8) at thread/qmutex.h:84
#6  QRecursiveMutexPrivate::lock(int) (this=0x5601db2ee2e0, timeout=timeout@entry=-1) at thread/qmutex.cpp:780
#7  0x00007f8637ecec69 in QMutex::lock() (this=this@entry=0x5601db2eed00) at thread/qmutex.cpp:235
#8  0x00007f858e6a1f67 in QMutexLocker::QMutexLocker(QBasicMutex*) (m=0x5601db2eed00, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:257
#9  QMutexLocker::QMutexLocker(QRecursiveMutex*) (m=0x5601db2eed00, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:262
#10 HistoryModel::clear() (this=0x5601db2eece0) at ./klipper/historymodel.cpp:26
#11 0x00007f858e69e1fd in History::slotClear() (this=<optimized out>) at ./klipper/history.cpp:113
#12 0x00007f858e68fe85 in Klipper::slotAskClearHistory() (this=0x5601dbe262a0) at ./klipper/klipper.h:83
#13 0x00007f858e680ef9 in ClipboardJob::start() (this=0x5601e3718180) at ./klipper/clipboardjob.cpp:38
#14 0x00007f86380e9ade in QObject::event(QEvent*) (this=0x5601e3718180, e=0x5601e3711ff0) at kernel/qobject.cpp:1347
#15 0x00007f8638d6c793 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x5601e3718180, e=0x5601e3711ff0) at kernel/qapplication.cpp:3640
#16 0x00007f86380bc07a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x5601e3718180, event=0x5601e3711ff0) at kernel/qcoreapplication.cpp:1064
#17 0x00007f86380bf167 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (receiver=0x0, event_type=0, data=0x5601d95baec0) at kernel/qcoreapplication.cpp:1821
#18 0x00007f8638116487 in postEventSourceDispatch(GSource*, GSourceFunc, gpointer) (s=0x5601d95fcce0) at kernel/qeventdispatcher_glib.cpp:277
#19 0x00007f8636bec569 in g_main_dispatch (context=0x7f862c005010) at ../../../glib/gmain.c:3444
#20 g_main_context_dispatch (context=0x7f862c005010) at ../../../glib/gmain.c:4162
#21 0x00007f8636c413c8 in g_main_context_iterate.constprop.0 (context=0x7f862c005010, block=<optimized out>, dispatch=1, self=<optimized out>) at ../../../glib/gmain.c:4238
#22 0x00007f8636be9d20 in g_main_context_iteration (context=0x7f862c005010, may_block=1) at ../../../glib/gmain.c:4303
#23 0x00007f8638115ad8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x5601d960f1c0, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#24 0x00007f86380ba99b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7fff31294ef0, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#25 0x00007f86380c2f34 in QCoreApplication::exec() () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#26 0x00007f86385364d0 in QGuiApplication::exec() () at kernel/qguiapplication.cpp:1870
#27 0x00007f8638d6c709 in QApplication::exec() () at kernel/qapplication.cpp:2832
#28 0x00005601d79e2a8b in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ./shell/main.cpp:235
---8<---

and then crashed with the same 'std::bad_alloc' uncaught exception (while the main thread is still stuck on the above trace).

After restarting, I can still see plasmashell freezing on HistoryModel::insert() for long stretches of time. I removed ~/.local/share/klipper/history2.lst and SIGKILLed plasmashell, and now it is behaving much better, as well as a lot of klipper problems I had are now no longer exhibiting.

I need to run it a bit longer to make sure, but even copying and pasting images seem to work fine now.

I have the copy of the klipper history file that was apparently giving me grief, if someone wants to try to analyze this. Putting the old history back in, it works for a bit until I select one of the copied images in the clipboard history menu, at which point I get this in the log:

Feb 09 13:37:23 vesho plasmashell[895012]: org.kde.klipper: Setting selection to < "β–¨ 1,610x1,329 32bpp" >
Feb 09 13:37:23 vesho plasmashell[895012]: org.kde.klipper: Setting clipboard to < "β–¨ 1,610x1,329 32bpp" >

Then we get frozen again at:

Thread 1 (Thread 0x7f7f541ba9c0 (LWP 893746) "plasmashell"):
#0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1  0x00007f7f586cea65 in QtLinuxFutex::_q_futex(int*, int, int, unsigned long long, int*, int) (val3=0, addr2=0x0, val2=0, val=3, op=0, addr=0x561762001048) at thread/qfutex_p.h:114
#2  QtLinuxFutex::futexWait<QBasicAtomicPointer<QMutexData> >(QBasicAtomicPointer<QMutexData>&, QBasicAtomicPointer<QMutexData>::Type) (expectedValue=0x3, futex=...) at thread/qfutex_p.h:133
#3  lockInternal_helper<false> (timeout=-1, elapsedTimer=0x0, d_ptr=...) at thread/qmutex_linux.cpp:142
#4  QBasicMutex::lockInternal() (this=0x561762001048) at thread/qmutex_linux.cpp:159
#5  0x00007f7f586ced73 in QBasicMutex::lock() (this=0x561762001048) at thread/qmutex.h:84
#6  QRecursiveMutexPrivate::lock(int) (this=0x561762001030, timeout=timeout@entry=-1) at thread/qmutex.cpp:780
#7  0x00007f7f586cec69 in QMutex::lock() (this=this@entry=0x561762001480) at thread/qmutex.cpp:235
#8  0x00007f7eb0319c80 in QMutexLocker::QMutexLocker(QBasicMutex*) (m=0x561762001480, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:257
#9  QMutexLocker::QMutexLocker(QRecursiveMutex*) (m=0x561762001480, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:262
#10 HistoryModel::moveToTop(int) (this=0x561762001460, row=row@entry=1) at ./klipper/historymodel.cpp:201
#11 0x00007f7eb0319dfc in HistoryModel::moveToTop(int) (row=1, this=<optimized out>) at ./klipper/historymodel.cpp:194
#12 0x00007f7eb0315253 in History::slotMoveToTop(QByteArray const&) (this=this@entry=0x561762001380, uuid=...) at ./klipper/history.cpp:137
#13 0x00007f7eb031530c in History::slotMoveToTop(QAction*) (this=0x561762001380, action=<optimized out>) at ./klipper/history.cpp:122
#14 0x00007f7f588f4108 in doActivate<false>(QObject*, int, void**) (sender=0x561761fcccf0, signal_index=9, argv=0x7fff4bc8a790) at kernel/qobject.cpp:3935
#15 0x00007f7f588ed177 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (sender=sender@entry=0x561761fcccf0, m=m@entry=0x7f7f59aa2ae0 <QMenu::staticMetaObject>, local_signal_index=local_signal_index@entry=2, argv=argv@entry=0x7fff4bc8a790) at kernel/qobject.cpp:3983
#16 0x00007f7f596f3026 in QMenu::triggered(QAction*) (this=this@entry=0x561761fcccf0, _t1=<optimized out>, _t1@entry=0x5617675ed3e0) at .moc/moc_qmenu.cpp:283
#17 0x00007f7f596fcbcb in QMenuPrivate::_q_actionTriggered() (this=0x561761f6d6b0) at widgets/qmenu.cpp:1486
#18 0x00007f7f588f4108 in doActivate<false>(QObject*, int, void**) (sender=0x5617675ed3e0, signal_index=4, argv=0x7fff4bc8a920) at kernel/qobject.cpp:3935
#19 0x00007f7f588ed177 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (sender=sender@entry=0x5617675ed3e0, m=m@entry=0x7f7f59a95d40 <QAction::staticMetaObject>, local_signal_index=local_signal_index@entry=1, argv=argv@entry=0x7fff4bc8a920) at kernel/qobject.cpp:3983
#20 0x00007f7f59565c56 in QAction::triggered(bool) (this=this@entry=0x5617675ed3e0, _t1=<optimized out>) at .moc/moc_qaction.cpp:376
#21 0x00007f7f5956894c in QAction::activate(QAction::ActionEvent) (this=0x5617675ed3e0, event=<optimized out>) at kernel/qaction.cpp:1161
#22 0x00007f7f596f4a52 in QMenuPrivate::activateCausedStack(QVector<QPointer<QWidget> > const&, QAction*, QAction::ActionEvent, bool) (this=this@entry=0x561761f6d6b0, causedStack=..., action=action@entry=0x5617675ed3e0, action_e=action_e@entry=QAction::Trigger, self=self@entry=true) at widgets/qmenu.cpp:1384
#23 0x00007f7f596fc629 in QMenuPrivate::activateAction(QAction*, QAction::ActionEvent, bool) (this=0x561761f6d6b0, action=0x5617675ed3e0, action_e=QAction::Trigger, self=<optimized out>) at widgets/qmenu.cpp:1461
#24 0x00007f7f596ff2ba in QMenu::keyPressEvent(QKeyEvent*) (this=<optimized out>, e=<optimized out>) at widgets/qmenu.cpp:3440
#25 0x00007f7eb031c03b in KlipperPopup::keyPressEvent(QKeyEvent*) (this=0x561761fcccf0, e=0x7fff4bc8afc0) at ./klipper/klipperpopup.cpp:251
#26 0x00007f7f595b0808 in QWidget::event(QEvent*) (this=0x561761fcccf0, event=0x7fff4bc8afc0) at kernel/qwidget.cpp:8704
#27 0x00007f7f5956c793 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=this@entry=0x56175fca8160, receiver=receiver@entry=0x561761fcccf0, e=e@entry=0x7fff4bc8afc0) at kernel/qapplication.cpp:3640
#28 0x00007f7f5957450e in QApplication::notify(QObject*, QEvent*) (this=<optimized out>, receiver=0x561761fcccf0, e=0x7fff4bc8afc0) at kernel/qapplication.cpp:3002
#29 0x00007f7f588bc07a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x561761fcccf0, event=0x7fff4bc8afc0) at kernel/qcoreapplication.cpp:1064
#30 0x00007f7f595cc4ff in QWidgetWindow::event(QEvent*) (this=0x561761ff3490, event=0x7fff4bc8afc0) at kernel/qwidgetwindow.cpp:293
#31 0x00007f7f5956c793 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x561761ff3490, e=0x7fff4bc8afc0) at kernel/qapplication.cpp:3640
#32 0x00007f7f588bc07a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x561761ff3490, event=0x7fff4bc8afc0) at kernel/qcoreapplication.cpp:1064
#33 0x00007f7f58d3ebea in QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) (e=0x56176911e4d0) at kernel/qguiapplication.cpp:2417
#34 0x00007f7f58d16a5c in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) (flags=...) at kernel/qwindowsysteminterface.cpp:1169
#35 0x00007f7f5a15f664 in userEventSourceDispatch(_GSource*, int (*)(void*), void*) () at /lib/x86_64-linux-gnu/libQt5WaylandClient.so.5
#36 0x00007f7f573f7569 in g_main_dispatch (context=0x7f7f4c005010) at ../../../glib/gmain.c:3444
#37 g_main_context_dispatch (context=0x7f7f4c005010) at ../../../glib/gmain.c:4162
#38 0x00007f7f5744c3c8 in g_main_context_iterate.constprop.0 (context=0x7f7f4c005010, block=<optimized out>, dispatch=1, self=<optimized out>) at ../../../glib/gmain.c:4238
#39 0x00007f7f573f4d20 in g_main_context_iteration (context=0x7f7f4c005010, may_block=1) at ../../../glib/gmain.c:4303
#40 0x00007f7f58915ad8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x56175fcc8b80, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#41 0x00007f7f588ba99b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7fff4bc8b250, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#42 0x00007f7f588c2f34 in QCoreApplication::exec() () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#43 0x00007f7f58d364d0 in QGuiApplication::exec() () at kernel/qguiapplication.cpp:1870
#44 0x00007f7f5956c709 in QApplication::exec() () at kernel/qapplication.cpp:2832
#45 0x000056175f138a8b in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ./shell/main.cpp:235

for definitely more than 5 minutes and then crash:

Feb 09 13:35:41 vesho plasmashell[893746]: QBuffer::writeData: Memory allocation error
Feb 09 13:35:41 vesho plasmashell[893746]: QBuffer::writeData: Memory allocation error
Feb 09 13:35:41 vesho plasmashell[893746]: libpng error: Write Error
Feb 09 13:35:41 vesho plasmashell[893746]: Qt Concurrent has caught an exception thrown from a worker thread.
                                           This is not supported, exceptions thrown in worker threads must be
                                           caught before control returns to Qt Concurrent.
Feb 09 13:35:41 vesho plasmashell[893746]: terminate called after throwing an instance of 'std::bad_alloc'
Feb 09 13:35:41 vesho plasmashell[893746]:   what():  std::bad_alloc

I think the origin of the problem is a screenshot I copied in which some of the area being copied was outside of any panel in my non-rectangular screen setup (I have a vertical screen next to a horizontal screen), and I have managed to paste (what I believe to be) the problematic image to GIMP and save it - if anyone is interested. I tried to reproduce the problem by copying similarly set up windows but have yet to succeed.

The PNG errors probably originate from this trace, but I can't be sure:

---8<---
Thread 16 (Thread 0x7f7f032d16c0 (LWP 893777) "Thread (pooled)"):
#0  0x00007f7f57275336 in png_write_row () at /lib/x86_64-linux-gnu/libpng16.so.16
#1  0x00007f7f5727689f in png_write_rows () at /lib/x86_64-linux-gnu/libpng16.so.16
#2  0x00007f7f58e0041f in QPNGImageWriter::writeImage(QImage const&, int, QString const&, int, int) (this=0x7f7f032d08f0, image=..., compression_in=-1, description=..., off_x_in=<optimized out>, off_y_in=<optimized out>) at image/qpnghandler.cpp:1174
#3  0x00007f7f58e00e0d in QPNGImageWriter::writeImage(QImage const&, int, QString const&) (description=..., compression=-1, img=..., this=0x7f7f032d08f0) at image/qpnghandler.cpp:181
#4  write_png_image (description=..., gamma=0, quality=-1, compression=-1, device=<optimized out>, image=...) at image/qpnghandler.cpp:1203
#5  QPngHandler::write(QImage const&) (this=<optimized out>, image=...) at image/qpnghandler.cpp:1250
#6  0x00007f7f58db9b15 in QImageWriter::write(QImage const&) (this=this@entry=0x7f7f032d09c8, image=...) at image/qimagewriter.cpp:785
#7  0x00007f7f58d8dff1 in operator<<(QDataStream&, QImage const&) (s=..., image=...) at image/qimage.cpp:3800
#8  0x00007f7eb031db95 in HistoryImageItem::write(QDataStream&) const (this=0x561762007350, stream=<optimized out>) at ./klipper/historyimageitem.cpp:44
#9  0x00007f7eb03040b9 in operator<<(QDataStream&, HistoryItem const*) (rhs=<optimized out>, lhs=...) at ./klipper/historyitem.h:119
#10 Klipper::saveHistory(bool) (this=0x7f7f44009a10, empty=<optimized out>) at ./klipper/klipper.cpp:528
#11 0x00007f7eb030856f in non-virtual thunk to QtConcurrent::RunFunctionTask<void>::run() () at /usr/lib/x86_64-linux-gnu/qt5/plugins/plasma/dataengine/plasma_engine_clipboard.so
#12 0x00007f7f586d19b2 in QThreadPoolThread::run() (this=0x561760ecbf80) at thread/qthreadpool.cpp:100
#13 0x00007f7f586ce703 in QThreadPrivate::start(void*) (arg=0x561760ecbf80) at thread/qthread_unix.cpp:330
#14 0x00007f7f57e90402 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#15 0x00007f7f57f1f590 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
---8<---
Comment 10 Bug Janitor Service 2023-02-11 07:15:11 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2607
Comment 12 Oded Arbel 2023-02-11 08:50:37 UTC
BTW, it happened again yesterday (while I was away from the computer);

Feb 10 18:54:04 vesho plasmashell[3480]: libpng error: Write Error
Feb 10 18:54:04 vesho plasmashell[3480]: QBuffer::writeData: Memory allocation error
Feb 10 18:54:04 vesho plasmashell[3480]: libpng error: Write Error
Feb 10 18:54:04 vesho plasmashell[3480]: QBuffer::writeData: Memory allocation error
Feb 10 18:54:04 vesho plasmashell[3480]: libpng error: Write Error
Feb 10 18:54:04 vesho plasmashell[3480]: QBuffer::writeData: Memory allocation error
Feb 10 18:54:04 vesho plasmashell[3480]: libpng error: Write Error
Feb 10 18:54:04 vesho plasmashell[3480]: QBuffer::writeData: Memory allocation error
Feb 10 18:54:04 vesho plasmashell[3480]: libpng error: Write Error
Feb 10 18:54:04 vesho plasmashell[3480]: Qt Concurrent has caught an exception thrown from a worker thread.
                                         This is not supported, exceptions thrown in worker threads must be
                                         caught before control returns to Qt Concurrent.
Feb 10 18:54:04 vesho plasmashell[3480]: terminate called after throwing an instance of 'std::bad_alloc'
Feb 10 18:54:04 vesho plasmashell[3480]:   what():  std::bad_alloc
Feb 10 18:54:04 vesho plasmashell[3480]: 25 -- exe=/usr/bin/plasmashell
Feb 10 18:54:04 vesho plasmashell[3480]: 17 -- platform=wayland
Feb 10 18:54:04 vesho plasmashell[3480]: 20 -- appname=plasmashell
Feb 10 18:54:04 vesho plasmashell[3480]: 17 -- apppath=/usr/bin
Feb 10 18:54:04 vesho plasmashell[3480]: 9 -- signal=6
Feb 10 18:54:04 vesho plasmashell[3480]: 9 -- pid=3480
Feb 10 18:54:04 vesho plasmashell[3480]: 19 -- appversion=5.27.80
Feb 10 18:54:04 vesho plasmashell[3480]: 19 -- programname=Plasma
Feb 10 18:54:04 vesho plasmashell[3480]: 31 -- bugaddress=submit@bugs.kde.org
Feb 10 18:54:04 vesho plasmashell[3480]: KCrash: crashing... crashRecursionCounter = 2
Feb 10 18:54:04 vesho plasmashell[3480]: KCrash: Application Name = plasmashell path = /usr/bin pid = 3480
Feb 10 18:54:04 vesho plasmashell[3480]: KCrash: Arguments: /usr/bin/plasmashell --no-respawn

And this was after I cleared the clipboard history and copied some new images into it - which didn't allow me to immediately reproduce the crash. Maybe it needs some rest time to reproduce... I'll try to build with the merge request next (but not today).
Comment 13 Oded Arbel 2023-02-11 08:53:02 UTC
And now it is frozen on:

Thread 1 (Thread 0x7fe0605689c0 (LWP 13998) "plasmashell"):
#0  syscall () at ../sysdeps/unix/sysv/linux/x86_64/syscall.S:38
#1  0x00007fe064acea65 in QtLinuxFutex::_q_futex(int*, int, int, unsigned long long, int*, int) (val3=0, addr2=0x0, val2=0, val=3, op=0, addr=0x561a5ba91628) at thread/qfutex_p.h:114
#2  QtLinuxFutex::futexWait<QBasicAtomicPointer<QMutexData> >(QBasicAtomicPointer<QMutexData>&, QBasicAtomicPointer<QMutexData>::Type) (expectedValue=0x3, futex=...) at thread/qfutex_p.h:133
#3  lockInternal_helper<false> (timeout=-1, elapsedTimer=0x0, d_ptr=...) at thread/qmutex_linux.cpp:142
#4  QBasicMutex::lockInternal() (this=0x561a5ba91628) at thread/qmutex_linux.cpp:159
#5  0x00007fe064aced73 in QBasicMutex::lock() (this=0x561a5ba91628) at thread/qmutex.h:84
#6  QRecursiveMutexPrivate::lock(int) (this=0x561a5ba91610, timeout=timeout@entry=-1) at thread/qmutex.cpp:780
#7  0x00007fe064acec69 in QMutex::lock() (this=this@entry=0x561a5ba94ed0) at thread/qmutex.cpp:235
#8  0x00007fdfb7b35100 in QMutexLocker::QMutexLocker(QBasicMutex*) (m=0x561a5ba94ed0, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:257
#9  QMutexLocker::QMutexLocker(QRecursiveMutex*) (m=0x561a5ba94ed0, this=<synthetic pointer>) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qmutex.h:262
#10 HistoryModel::insert(std::shared_ptr<HistoryItem>) (this=0x561a5ba94eb0, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/historymodel.cpp:135
#11 0x00007fdfb7b300d2 in History::insert(std::shared_ptr<HistoryItem>) (this=<optimized out>, item=std::shared_ptr<HistoryItem> (use count 3, weak count 0) = {...}) at ./klipper/history.cpp:95
#12 0x00007fdfb7b1a166 in Klipper::applyClipChanges(QMimeData const*) (this=this@entry=0x561a5ba66940, clipData=clipData@entry=0x561a61f5eb20) at ./klipper/klipper.cpp:687
#13 0x00007fdfb7b1ca48 in Klipper::checkClipData(bool) (this=0x561a5ba66940, selectionMode=<optimized out>) at ./klipper/klipper.cpp:828
#14 0x00007fe064cf40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffdab7519e0, r=0x561a5ba66940, this=0x561a5ba94dd0) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#15 doActivate<false>(QObject*, int, void**) (sender=0x561a5ba95010, signal_index=3, argv=0x7ffdab7519e0) at kernel/qobject.cpp:3923
#16 0x00007fe0644240a2 in KSystemClipboard::changed(QClipboard::Mode) () at /lib/x86_64-linux-gnu/libKF5GuiAddons.so.5
#17 0x00007fe064cf40d4 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffdab751a90, r=0x561a5ba95010, this=0x561a5ba85eb0) at ../../include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:398
#18 doActivate<false>(QObject*, int, void**) (sender=0x561a59946e80, signal_index=3, argv=0x7ffdab751a90) at kernel/qobject.cpp:3923
#19 0x00007fe066495e2e in ffi_call_unix64 () at ../src/x86/unix64.S:105
#20 0x00007fe066492493 in ffi_call_int (cif=<optimized out>, fn=<optimized out>, rvalue=<optimized out>, avalue=<optimized out>, closure=<optimized out>) at ../src/x86/ffi64.c:672
#21 0x00007fe067088b20 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#22 0x00007fe0670892c3 in  () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#23 0x00007fe0670894bc in wl_display_dispatch_queue_pending () at /lib/x86_64-linux-gnu/libwayland-client.so.0
#24 0x00007fe06652338a in QtWaylandClient::QWaylandDisplay::flushRequests() (this=<optimized out>) at ./src/client/qwaylanddisplay.cpp:253
#25 0x00007fe064ce9ade in QObject::event(QEvent*) (this=0x561a5992cb50, e=0x7fe05400be20) at kernel/qobject.cpp:1347
#26 0x00007fe06596c793 in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x561a5992cb50, e=0x7fe05400be20) at kernel/qapplication.cpp:3640
#27 0x00007fe064cbc07a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x561a5992cb50, event=0x7fe05400be20) at kernel/qcoreapplication.cpp:1064
#28 0x00007fe064cbf167 in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) (receiver=0x0, event_type=0, data=0x561a59903ec0) at kernel/qcoreapplication.cpp:1821
#29 0x00007fe064d16487 in postEventSourceDispatch(GSource*, GSourceFunc, gpointer) (s=0x561a59945d60) at kernel/qeventdispatcher_glib.cpp:277
#30 0x00007fe0637bb569 in g_main_dispatch (context=0x7fe058005010) at ../../../glib/gmain.c:3444
#31 g_main_context_dispatch (context=0x7fe058005010) at ../../../glib/gmain.c:4162
#32 0x00007fe0638103c8 in g_main_context_iterate.constprop.0 (context=0x7fe058005010, block=<optimized out>, dispatch=1, self=<optimized out>) at ../../../glib/gmain.c:4238
#33 0x00007fe0637b8d20 in g_main_context_iteration (context=0x7fe058005010, may_block=1) at ../../../glib/gmain.c:4303
#34 0x00007fe064d15ad8 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x561a5994ab70, flags=...) at kernel/qeventdispatcher_glib.cpp:423
#35 0x00007fe064cba99b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7ffdab752250, flags=..., flags@entry=...) at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#36 0x00007fe064cc2f34 in QCoreApplication::exec() () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#37 0x00007fe0651364d0 in QGuiApplication::exec() () at kernel/qguiapplication.cpp:1870
#38 0x00007fe06596c709 in QApplication::exec() () at kernel/qapplication.cpp:2832
#39 0x0000561a58b58a8b in main(int, char**) (argc=<optimized out>, argv=<optimized out>) at ./shell/main.cpp:235
Comment 14 Bug Janitor Service 2023-02-11 16:32:59 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2608
Comment 15 Oliver Hiorns 2023-02-12 04:31:46 UTC
If you can reproduce this again, could you keep the system monitor open and watch memory usage?

It seems like the crash might be caused by the system running out of memory, and the freeze-up is because of an infinite loop that keeps trying to save the same image again and again to the save file (in memory - it crashes before it gets committed to disk).

So, if the theory is correct, while it is frozen, memory usage will increase steadily, and when you run out of memory then it will crash. Being able to confirm this would be good.
Comment 16 Bug Janitor Service 2023-02-12 04:34:54 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2609
Comment 17 Oliver Hiorns 2023-02-12 05:35:45 UTC
MR 2609 should fix this, no need to reproduce any more.
Comment 18 Bug Janitor Service 2023-02-12 16:31:01 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2612
Comment 19 Fushan Wen 2023-02-13 00:28:23 UTC
Git commit 4649594aa95d601ac6449c9e8baf8201b28602c5 by Fushan Wen.
Committed on 12/02/2023 at 15:38.
Pushed by fusionfuture into branch 'master'.

klipper: store QImage and construct QPixmap only when necessary

The mime data from Wayland clipboard is not the exact same image, so two
image items are listed (first time restarting plasmashell). But after
images are saved to local, they have the same uuid again. So klipper
starts to become confused after the second time restarting plasmashell.

This is caused by QPixmap::from(QImage).toImage() erasing metadata in the
image, and KSystemClipboard will emit changed signal on Wayland, so
another identical image is added to clipboard.
Related: bug 465225, bug 464828, bug 465603
FIXED-IN: 5.27

M  +5    -5    klipper/historyimageitem.cpp
M  +2    -2    klipper/historyimageitem.h
M  +3    -4    klipper/historyitem.h

https://invent.kde.org/plasma/plasma-workspace/commit/4649594aa95d601ac6449c9e8baf8201b28602c5
Comment 20 Fushan Wen 2023-02-13 00:29:33 UTC
Git commit 41ac399c39a653cac1d63b3f1913ed4eb2f0d2c3 by Fushan Wen.
Committed on 13/02/2023 at 00:29.
Pushed by fusionfuture into branch 'cherry-pick-4649594a'.

klipper: store QImage and construct QPixmap only when necessary

The mime data from Wayland clipboard is not the exact same image, so two
image items are listed (first time restarting plasmashell). But after
images are saved to local, they have the same uuid again. So klipper
starts to become confused after the second time restarting plasmashell.

This is caused by QPixmap::from(QImage).toImage() erasing metadata in the
image, and KSystemClipboard will emit changed signal on Wayland, so
another identical image is added to clipboard.
Related: bug 465225, bug 464828, bug 465603
FIXED-IN: 5.27


(cherry picked from commit 4649594aa95d601ac6449c9e8baf8201b28602c5)

M  +5    -5    klipper/historyimageitem.cpp
M  +2    -2    klipper/historyimageitem.h
M  +3    -4    klipper/historyitem.h

https://invent.kde.org/plasma/plasma-workspace/commit/41ac399c39a653cac1d63b3f1913ed4eb2f0d2c3
Comment 21 Fushan Wen 2023-02-13 00:47:31 UTC
Git commit 89d1f0e07955427a083cbc5af34e0ae9fdcdaad4 by Fushan Wen.
Committed on 13/02/2023 at 00:46.
Pushed by fusionfuture into branch 'Plasma/5.27'.

klipper: store QImage and construct QPixmap only when necessary

The mime data from Wayland clipboard is not the exact same image, so two
image items are listed (first time restarting plasmashell). But after
images are saved to local, they have the same uuid again. So klipper
starts to become confused after the second time restarting plasmashell.

This is caused by QPixmap::from(QImage).toImage() erasing metadata in the
image, and Wayland clipboard is async, so another identical image is added
to clipboard.
Related: bug 465225, bug 464828, bug 465603
FIXED-IN: 5.27


(cherry picked from commit 4649594aa95d601ac6449c9e8baf8201b28602c5)

M  +5    -5    klipper/historyimageitem.cpp
M  +2    -2    klipper/historyimageitem.h
M  +3    -4    klipper/historyitem.h

https://invent.kde.org/plasma/plasma-workspace/commit/89d1f0e07955427a083cbc5af34e0ae9fdcdaad4
Comment 22 Fushan Wen 2023-02-13 11:17:57 UTC

*** This bug has been marked as a duplicate of bug 465225 ***
Comment 23 Fushan Wen 2023-02-13 18:16:18 UTC
Git commit 365bd94bc6b4de910249f566b01a22bacfb55353 by Fushan Wen.
Committed on 13/02/2023 at 16:34.
Pushed by fusionfuture into branch 'master'.

klipper: lock mutex before `indexOf` in `insert`
Related: bug 465225

M  +2    -1    klipper/historymodel.cpp

https://invent.kde.org/plasma/plasma-workspace/commit/365bd94bc6b4de910249f566b01a22bacfb55353