Bug 484687

Summary: On X11, plasma crashes in ScreenPool::handleScreenRemoved after waking monitor
Product: [Plasma] plasmashell Reporter: sp <sp139>
Component: generic-crashAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED FIXED    
Severity: crash CC: dougshaw77, itsbugfood, kde, meven29, nate, nicolas.fella, notmart, okitain, postix, salamanetwork, tkaratzo
Priority: NOR Keywords: drkonqi
Version: 6.0.3   
Target Milestone: 1.0   
Platform: unspecified   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=444386
Latest Commit: Version Fixed In: 6.2.0
Sentry Crash Report: https://crash-reports.kde.org/organizations/kde/issues/3211/
Attachments: New crash information added by DrKonqi

Description sp 2024-03-28 22:49:08 UTC
Application: plasmashell (6.0.3)

Qt Version: 6.6.2
Frameworks Version: 6.0.0
Operating System: Linux 6.5.0-26-generic x86_64
Windowing System: X11
Distribution: KDE neon 6.0
DrKonqi: 6.0.3 [CoredumpBackend]

-- Information about the crash:
monitor goes to sleep.  After pressing a key to wake it up, plasma crashes.

The crash can be reproduced sometimes.

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


Reported using DrKonqi
Comment 1 sp 2024-03-28 22:49:09 UTC
Created attachment 167906 [details]
New crash information added by DrKonqi

DrKonqi auto-attaching complete backtrace.
Comment 2 Nicolas Fella 2024-03-29 00:00:56 UTC
#6  __pthread_kill_implementation (no_tid=0, signo=6, threadid=125444339747520) at ./nptl/pthread_kill.c:44
#7  __pthread_kill_internal (signo=6, threadid=125444339747520) at ./nptl/pthread_kill.c:78
#8  __GI___pthread_kill (threadid=125444339747520, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#9  0x000072174d442476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#10 0x000072174d4287f3 in __GI_abort () at ./stdlib/abort.c:79
#11 0x000072174e0db597 in qAbort () at ./src/corelib/global/qglobal.cpp:161
#12 0x000072174e0d67f5 in qt_message_fatal<QString&> (message=..., context=...) at ./src/corelib/global/qlogging.cpp:2003
#13 qt_message(QtMsgType, const QMessageLogContext &, const char *, typedef __va_list_tag __va_list_tag *) (msgType=msgType@entry=QtFatalMsg, context=..., msg=<optimized out>, ap=ap@entry=0x7fffefc3fcd0) at ./src/corelib/global/qlogging.cpp:378
#14 0x000072174e0dbfc3 in QMessageLogger::fatal (this=<optimized out>, msg=<optimized out>) at ./src/corelib/global/qlogging.cpp:901
#15 0x000072174e0a0387 in qt_assert_x (where=where@entry=0x5d49db706d88 "void ScreenPool::handleScreenRemoved(QScreen*)", what=<optimized out>, file=file@entry=0x5d49db70700f "./shell/screenpool.cpp", line=line@entry=265) at ./src/corelib/global/qassert.cpp:77
#16 0x00005d49db64fa10 in ScreenPool::handleScreenRemoved (this=0x5d49dd19b4d0, screen=<optimized out>) at ./shell/screenpool.cpp:265
#17 0x000072174e03c3ce in QtPrivate::QSlotObjectBase::call (a=<optimized out>, r=<optimized out>, this=<optimized out>, this=<optimized out>, r=<optimized out>, a=<optimized out>) at ./src/corelib/kernel/qobjectdefs_impl.h:433
#18 doActivate<false> (sender=0x7fffefc407e0, signal_index=10, argv=0x7fffefc40000) at ./src/corelib/kernel/qobject.cpp:4039
#19 0x000072174e4f2646 in QGuiApplication::screenRemoved (this=<optimized out>, _t1=<optimized out>) at ./obj-x86_64-linux-gnu/src/gui/Gui_autogen/include/moc_qguiapplication.cpp:560
#20 0x000072174e54cc02 in QWindowSystemInterface::handleScreenRemoved (platformScreen=0x5d49def4d6f0) at ./src/corelib/kernel/qcoreapplication.h:96
#21 0x00007217489b155c in QXcbConnection::initializeScreensFromMonitor (this=this@entry=0x5d49dcdbab80, it=it@entry=0x7fffefc40240, xcbScreenNumber=xcbScreenNumber@entry=0, primaryScreen=primaryScreen@entry=0x7fffefc40220, initialized=initialized@entry=true) at ./src/plugins/platforms/xcb/qxcbconnection_screens.cpp:567
#22 0x00007217489b1b58 in QXcbConnection::initializeScreens (this=0x5d49dcdbab80, initialized=true) at ./src/plugins/platforms/xcb/qxcbconnection_screens.cpp:317
#23 0x00007217489a6ae2 in QXcbConnection::handleXcbEvent (this=0x5d49dcdbab80, event=0x5d49dd8c0da0) at ./src/plugins/platforms/xcb/qxcbconnection.cpp:590
#24 0x00007217489ad0ee in QXcbConnection::processXcbEvents (this=0x5d49dcdbab80, flags=...) at ./src/plugins/platforms/xcb/qxcbconnection.cpp:1087
#25 0x00007217489c4a87 in xcbSourceDispatch (source=<optimized out>) at ./src/plugins/platforms/xcb/qxcbeventdispatcher.cpp:55
#26 0x000072174c8e1d3b in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#27 0x000072174c937258 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#28 0x000072174c8df3e3 in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#29 0x000072174de55c30 in QEventDispatcherGlib::processEvents (this=0x5d49dce6f520, flags=...) at ./src/corelib/kernel/qeventdispatcher_glib.cpp:393
#30 0x000072174e07fceb in QEventLoop::exec (this=0x7fffefc40700, flags=...) at ./src/corelib/global/qflags.h:34
#31 0x000072174e07a36c in QCoreApplication::exec () at ./src/corelib/global/qflags.h:74
#32 0x000072174e4e9a20 in QGuiApplication::exec () at ./src/gui/kernel/qguiapplication.cpp:1925
#33 0x00007217501ee469 in QApplication::exec () at ./src/widgets/kernel/qapplication.cpp:2574
#34 0x00005d49db652bb4 in main (argc=<optimized out>, argv=<optimized out>) at ./shell/main.cpp:214
Comment 3 sp 2024-04-08 04:59:19 UTC
Video driver is amdgpu.
More or less 9 times out 10, when monitor goes to powersave/sleep, when waking it up, plasmashell crashes. So it almost always crashes.
"Crash report" lets us send "automatic" crash report. So I've been sending them also.
Comment 4 Nate Graham 2024-04-08 16:50:24 UTC
Thanks, that's indeed helpful to do.
Comment 5 Marco Martin 2024-04-15 12:10:50 UTC
https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4238 *might* fix that, at least fixes it for the way i could reproduce (disabling internal monitor and enabling external in one go from the kcm) needs to see if it will make sentry reports go down
Comment 6 Marco Martin 2024-04-15 12:36:41 UTC
Git commit dfd160bdf6f660c10b712a664c86a2a7339e8e72 by Marco Martin.
Committed on 15/04/2024 at 12:36.
Pushed by mart into branch 'master'.

Fix redundantoutputs when the enabled screens change very quickly

on X11, when a single transaction from KScreen disables screenA and
enabled screenB, a new output order arrivers before the old output gets removed
 and in that moment the new screen will be considered redundant to che screen
that is about to be removed, causing an invalid internal state
Related: bug 456947

M  +4    -3    shell/screenpool.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/dfd160bdf6f660c10b712a664c86a2a7339e8e72
Comment 7 Bug Janitor Service 2024-04-15 12:37:41 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4239
Comment 8 Marco Martin 2024-04-15 12:57:00 UTC
Git commit da35849d5f4913221ba362d3961fd29526f364d5 by Marco Martin.
Committed on 15/04/2024 at 12:37.
Pushed by mart into branch 'Plasma/6.0'.

Fix redundantoutputs when the enabled screens change very quickly

on X11, when a single transaction from KScreen disables screenA and
enabled screenB, a new output order arrivers before the old output gets removed
 and in that moment the new screen will be considered redundant to che screen
that is about to be removed, causing an invalid internal state
Related: bug 456947


(cherry picked from commit dfd160bdf6f660c10b712a664c86a2a7339e8e72)

c6ff79fd Fix redundantoutputs when the enabled screens change very quickly

M  +4    -3    shell/screenpool.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/da35849d5f4913221ba362d3961fd29526f364d5
Comment 9 Nate Graham 2024-05-10 13:59:37 UTC
That commit made it into Plasma 6.0.4, which has been released for a few weeks now. We think this may have resolved the issue fully; closing the bug report. However please do feel free to re-open if if you can still reproduce the crash with 6.0.4 or later.

If you do, make sure it's the exact same crash, with the same backtrace.

Thanks!
Comment 10 Méven Car 2024-07-17 10:54:04 UTC
We still have a lot of crashes in KDE Neon with Plasma 6.1.2:

```
KCrash: Application 'plasmashell' crashing... crashRecursionCounter = 2
ASSERT failure in void ScreenPool::handleScreenRemoved(QScreen*): "ScreenPool ( 0x62adc81a8310 ) Internal state:
 Screen Order:	 QList(QScreen(0x7285680235f0, name="DP-0")) 
 "Fake" screens:	 QSet() 
 Redundant screens covered by other ones:	 QHash() 
 All screens, ordered by size:	 QList(QScreen(0x7285680235f0, name="DP-0")) 
 All screen that QGuiApplication knows:	 QList(QScreen(0x7285680235f0, name="DP-0")) 
 Current screen: QScreen(0x62adc78cd610, name=":0.0") ", file ./shell/screenpool.cpp, line 261
```

https://crash-reports.kde.org/organizations/kde/issues/3211/?project=9&query=is%3Aunresolved&referrer=issue-stream&stream_index=1
Comment 11 Akseli Lahtinen 2024-07-18 07:57:15 UTC
*** Bug 490426 has been marked as a duplicate of this bug. ***
Comment 12 Nate Graham 2024-07-19 18:27:01 UTC
See also older bug reports that have QScreen in the backtrace: Bug 454057. This one doesn't, though both end up in ScreenPool::handleScreenRemoved.
Comment 13 cwo 2024-07-30 10:35:15 UTC
*** Bug 490993 has been marked as a duplicate of this bug. ***
Comment 14 Nate Graham 2024-07-30 21:30:20 UTC
*** Bug 486863 has been marked as a duplicate of this bug. ***
Comment 15 Bug Janitor Service 2024-08-24 13:30:07 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4642
Comment 16 duha.bugs 2024-08-27 18:46:08 UTC
*** Bug 492273 has been marked as a duplicate of this bug. ***
Comment 17 Méven 2024-08-31 07:47:42 UTC
Git commit 7975ecf9631b01650f24c1f98582907e1bc3ddb6 by Méven Car.
Committed on 31/08/2024 at 07:30.
Pushed by meven into branch 'master'.

ScreenPool: add fake screens initially

So that fake screens at the gui starts are in m_fakeScreens.

M  +49   -0    shell/autotests/screenpooltest.cpp
M  +5    -0    shell/screenpool.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/7975ecf9631b01650f24c1f98582907e1bc3ddb6
Comment 18 Méven 2024-09-08 09:16:17 UTC
Git commit ac473d8e358ac8a0f25a6236673b8aeccc3822df by Méven Car.
Committed on 08/09/2024 at 09:16.
Pushed by meven into branch 'Plasma/6.1'.

ScreenPool: add fake screens initially

So that fake screens at the gui starts are in m_fakeScreens.
(cherry picked from commit 7975ecf9631b01650f24c1f98582907e1bc3ddb6)

M  +49   -0    shell/autotests/screenpooltest.cpp
M  +5    -0    shell/screenpool.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/ac473d8e358ac8a0f25a6236673b8aeccc3822df
Comment 19 Méven Car 2024-09-16 10:17:50 UTC
https://crash-reports.kde.org/organizations/kde/issues/3211/?project=9&query=is%3Aunresolved+issue.priority%3A%5Bhigh%2C+medium%5D&referrer=issue-stream&statsPeriod=14d&stream_index=2

Not fixed:
```
default
ASSERT failure in void ScreenPool::handleScreenRemoved(QScreen*): "ScreenPool ( 0x643342b05c00 ) Internal state:
 Screen Order:	 QList(QScreen(0x64334695ae60, name="HDMI-A-0")) 
 "Fake" screens:	 QSet() 
 Redundant screens covered by other ones:	 QHash() 
 All screens, ordered by size:	 QList(QScreen(0x64334695ae60, name="HDMI-A-0")) 
 All screen that QGuiApplication knows:	 QList(QScreen(0x64334695ae60, name="HDMI-A-0")) 
 Current screen: QScreen(0x64334273faa0, name=":0.0") ", file ./shell/screenpool.cpp, line 266
```

Fake screen can still be not added to `m_fakeScreens`.
Comment 20 Bug Janitor Service 2024-09-16 10:55:52 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4704
Comment 21 Nate Graham 2024-09-25 21:01:26 UTC
*** Bug 454057 has been marked as a duplicate of this bug. ***
Comment 22 Nate Graham 2024-09-25 21:01:28 UTC
*** Bug 461605 has been marked as a duplicate of this bug. ***
Comment 23 Nate Graham 2024-09-25 21:01:31 UTC
*** Bug 463396 has been marked as a duplicate of this bug. ***
Comment 24 Bug Janitor Service 2024-09-27 11:23:51 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/4761
Comment 25 Marco Martin 2024-09-30 09:32:18 UTC
Git commit b833966ad2e56714eddc999420dec24f7fa3e0cd by Marco Martin.
Committed on 30/09/2024 at 09:32.
Pushed by mart into branch 'master'.

outputorderwatcher: watch for when the last output is removed

watch for XCB_RANDR_CONNECTION_DISCONNECTED to immediately remove from
the screen order, to avoid the data inconsistency when the last screen
gets removed

When the ast screen is removed, its qscreen becomes name ":0.0" as the fake screen, but nothing happens really,
screenpool doesn't notice (and looking at the assert_x there are, that was expected"
then the screen gets connected again, a new screen gets conencted, the old 0.0 one
gets disconnected, but the screen order stuff doesn't say anything as it's still
the same connector name as before so screenpool finds itself with an empty screenorder

M  +26   -0    libkworkspace/outputorderwatcher.cpp
M  +0    -5    shell/screenpool.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/b833966ad2e56714eddc999420dec24f7fa3e0cd
Comment 26 Marco Martin 2024-09-30 09:55:55 UTC
Git commit 27e16b504b96a717691abe5cef63e9fdc3ee0670 by Marco Martin.
Committed on 30/09/2024 at 09:37.
Pushed by mart into branch 'Plasma/6.2'.

outputorderwatcher: watch for when the last output is removed

watch for XCB_RANDR_CONNECTION_DISCONNECTED to immediately remove from
the screen order, to avoid the data inconsistency when the last screen
gets removed

When the ast screen is removed, its qscreen becomes name ":0.0" as the fake screen, but nothing happens really,
screenpool doesn't notice (and looking at the assert_x there are, that was expected"
then the screen gets connected again, a new screen gets conencted, the old 0.0 one
gets disconnected, but the screen order stuff doesn't say anything as it's still
the same connector name as before so screenpool finds itself with an empty screenorder


(cherry picked from commit b833966ad2e56714eddc999420dec24f7fa3e0cd)

16c98c28 outputorderwatcher: watch for when the last output is removed
9aec2c7a add comments on what's going on
b1911f16 more comments

Co-authored-by: Marco Martin <notmart@gmail.com>

M  +26   -0    libkworkspace/outputorderwatcher.cpp
M  +0    -5    shell/screenpool.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/27e16b504b96a717691abe5cef63e9fdc3ee0670