Bug 453124 - VSCodium consistently crashes Plasmashell with SIGSEGV
Summary: VSCodium consistently crashes Plasmashell with SIGSEGV
Status: RESOLVED FIXED
Alias: None
Product: kwayland
Classification: Frameworks and Libraries
Component: client (show other bugs)
Version: 5.93.0
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Martin Flöser
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-28 09:16 UTC by Bart Ribbers
Modified: 2022-09-26 07:46 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Log of plasmashell --replace with it crashing (5.32 KB, text/x-log)
2022-04-28 09:16 UTC, Bart Ribbers
Details
Backtrace of plasmashell SIGSEGV'ing (7.61 KB, text/x-log)
2022-04-29 06:21 UTC, Bart Ribbers
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bart Ribbers 2022-04-28 09:16:44 UTC
Created attachment 148425 [details]
Log of plasmashell --replace with it crashing

SUMMARY
When VSCodium is launched or already running, plasmashell instantly crashes with SIGSEGV.


STEPS TO REPRODUCE
1. Launch VSCodium

OBSERVED RESULT
Plasmashell crashes

EXPECTED RESULT
Plasmashell to not crash

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Alpine Linux
(available in About System)
KDE Plasma Version: 5.24.4
KDE Frameworks Version: 5.93.0
Qt Version: 5.15.3 with KDE patches

ADDITIONAL INFORMATION
Since my host is Alpine Linux which uses Musl libc and Electron applications do not work with it, I run VSCodium in https://github.com/89luca89/distrobox. However other graphical applications like Firefox run just fine, so I doubt that has much to do with it.
Comment 1 Fabian Vogt 2022-04-28 09:25:57 UTC
I don't see a crash in the attached log.

Can you get a backtrace?
Comment 2 Bart Ribbers 2022-04-29 06:21:29 UTC
Created attachment 148452 [details]
Backtrace of plasmashell SIGSEGV'ing

Seems it goes wrong somewhere in KWayland? Please let me know if I need to get debug symbols for libQt5Core.
Comment 3 Fabian Vogt 2022-04-29 10:22:21 UTC
Each call to readData allocates > 4KiB on stack, which with recursion that deep might blow the limits of the thread.
Can you somehow increase the thread's default stack size to ~2MiB?

The function could be improved to avoid recursion (and unbounded delay), can you try that?

diff --git a/src/client/plasmawindowmanagement.cpp b/src/client/plasmawindowmanagement.cpp
index 0098c728..903e5342 100644
--- a/src/client/plasmawindowmanagement.cpp
+++ b/src/client/plasmawindowmanagement.cpp
@@ -631,16 +631,14 @@ static int readData(int fd, QByteArray &data)
     int n;
     while (true) {
         n = QT_READ(fd, buf, sizeof buf);
-        if (n == -1 && (errno == EAGAIN) && ++retryCount < 1000) {
+        f (n > 0) {
+            data.append(buf, n);
+        } else if (n == -1 && (errno == EAGAIN) && ++retryCount < 1000) {
             usleep(1000);
         } else {
             break;
         }
     }
-    if (n > 0) {
-        data.append(buf, n);
-        n = readData(fd, data);
-    }
     return n;
 }
Comment 4 Fabian Vogt 2022-04-29 10:25:57 UTC
(In reply to Fabian Vogt from comment #3)
> -        if (n == -1 && (errno == EAGAIN) && ++retryCount < 1000) {
> +        f (n > 0) {

Copy-paste error. I just opened a draft MR: https://invent.kde.org/frameworks/kwayland/-/merge_requests/61
Comment 5 Bug Janitor Service 2022-05-14 04:35:18 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Bart Ribbers 2022-05-23 19:12:04 UTC
Not sure what info it needs more. https://invent.kde.org/frameworks/kwayland/-/merge_requests/61 fixes the issue and I have been shipping it on Alpine Linux so far, hoping it or something comparable gets merged eventually.
Comment 7 Fabian Vogt 2022-09-26 07:46:03 UTC
Git commit d0edf838f142114d9074c1ff54f420da47cc92c3 by Fabian Vogt.
Committed on 23/09/2022 at 10:18.
Pushed by fvogt into branch 'master'.

PlasmaWindowManagement: Avoid unbounded recursion and delay in readData

It recurses for each partial read, which can lead to unbounded recursion depth
and delay (retryCount isn't passed). Convert the code to be iterative to fix
that, which is also much simpler.

M  +3    -5    src/client/plasmawindowmanagement.cpp

https://invent.kde.org/frameworks/kwayland/commit/d0edf838f142114d9074c1ff54f420da47cc92c3