Bug 428268

Summary: kwin_wayland crashes when pipewire stopped
Product: [Plasma] kwin Reporter: Fabian Vogt <fabian>
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: crash CC: alois1, bugseforuns, goduck777, herzenschein, joern.koerner, kde.lq8hx, kde, mihnerts, nate, openmail+kde
Priority: NOR Keywords: wayland
Version: 5.21.2   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=439455
Latest Commit: Version Fixed In: 5.22
Sentry Crash Report:
Attachments: Crash log
logs of kwin_wayland crashes with pipewire
kwin pipewire crash backtrace

Description Fabian Vogt 2020-10-26 10:46:27 UTC
1. Start kwin_wayland
2. Make sure pipewire is running
3. Hover over window icons to create a pipewire connection
4. Stop pipewire (Ctrl-C, killall, systemctl --user stop, whatever)

If this doesn't lead to a kwin_wayland crash, repeat steps 2-4.
Comment 1 Thiago Sueto 2020-11-07 06:29:08 UTC
Created attachment 133102 [details]
Crash log

This is always reproducible.
Adding a crash log made with gdb attached to kwin_wayland
I used the following command:

sudo gdb -pid $(pidof kwin_wayland) -batch -ex "set logging file kwin_wayland_pipewirestop.txt" -ex "set logging on" -ex "continue" -ex "thread apply all backtrace" -ex "quit"
Comment 2 Thiago Sueto 2020-11-07 06:35:53 UTC
Just noticed that crash log doesn't have info in the one thread that is needed...
Is it even possible to get backtraces for kwin_wayland? How?
Comment 3 Schlaefer 2021-02-21 15:29:02 UTC
Created attachment 136015 [details]
logs of kwin_wayland crashes with pipewire

I'm using pipewire with wayland. Trying to debug issues with pipewire I run

    systemctl --user stop pipewire.service; systemctl --user stop pipewire.socket;

to stop pipewire and kwin_wayland crashes relatively consistently, esp. the first time after booting.

The attachment has logs of crashes that happen after said command.

Operating System: EndeavourOS
KDE Plasma Version: 5.21.0
KDE Frameworks Version: 5.79.0
Qt Version: 5.15.2
Kernel Version: 5.10.16-zen1-1-zen
OS Type: 64-bit
Graphics Platform: Wayland
Graphics Processor: Radeon RX 5500 XT
Comment 4 Joern 2021-03-09 18:46:27 UTC
Created attachment 136535 [details]
kwin pipewire crash backtrace

1. Start a kwin_waylan session
2. Open some windows
3. Randomly click these windows in the taskbar. (Differs from 5-30x)

I've a very similar if not the same problem.
Running KDE 5.21.2 Wayland.

Whenever kwin_wayland crashes there is always a pipewire message in the logs 1-3 seconds before. See logs/backtrace.

Mär 09 18:30:57 XPS7590 pipewire[2218]: protocol-native 0x55b30f070ca0: client 0x55b30f1a9150 error -9 (Bad file descriptor)
Mär 09 18:30:57 XPS7590 pipewire[2218]: mempool 0x55b30f063020: Failed to create memfd: Too many open files

While
$ sysctl fs.file-nr
fs.file-nr = 18848      0       9223372036854775807


Interestingly kwin 5.20.5 was stable.
Comment 5 Fabian Vogt 2021-03-09 18:52:55 UTC
(In reply to Joern from comment #4)
> Created attachment 136535 [details]
> kwin pipewire crash backtrace
> 
> 1. Start a kwin_waylan session
> 2. Open some windows
> 3. Randomly click these windows in the taskbar. (Differs from 5-30x)
> 
> I've a very similar if not the same problem.
> Running KDE 5.21.2 Wayland.
> 
> Whenever kwin_wayland crashes there is always a pipewire message in the logs
> 1-3 seconds before. See logs/backtrace.
> 
> Mär 09 18:30:57 XPS7590 pipewire[2218]: protocol-native 0x55b30f070ca0:
> client 0x55b30f1a9150 error -9 (Bad file descriptor)
> Mär 09 18:30:57 XPS7590 pipewire[2218]: mempool 0x55b30f063020: Failed to
> create memfd: Too many open files

Apparently Kwin doesn't handle this failure gracefully, it probably passes
some invalid values further down the chain until it crashes in the graphics
driver (?):

Mar 09 18:57:32 XPS7590 kernel: kwin_wayland[914]: segfault at 7fa7a42480d8 ip 00007fa7a42480d8 sp 00007ffcf4c13dd0 error 14 in anon_inode:i915.gem[7fa7a42ff000+c0000]

Sounds like a different issue, or actually two: Opening too many files
(whatever the reason is) and missing (?) error handling.
Comment 6 Joern 2021-03-10 07:36:33 UTC
@Fabian

You might be right. Since I've about 5-30 crashes a day I searched deeper into the journal. It is not always i915 driver. It differs from time to time.

Mär 10 07:53:58 XPS7590 kernel: kwin_wayland[2545]: segfault at 7ff10464c0d8 ip 00007ff10464c0d8 sp 00007ffea171bbb0 error 14 in memfd:wayland-cursor (deleted)[7ff10467b000+120000]
Mär 09 18:30:57 XPS7590 kernel: kwin_wayland[9525]: segfault at 7f26bc1110d8 ip 00007f26bc1110d8 sp 00007ffc95b7f2a0 error 14
Mär 09 12:17:28 XPS7590 kernel: kwin_wayland[918]: segfault at 7f60514fe0d8 ip 00007f60514fe0d8 sp 00007ffc4192cb70 error 14 in libspa-support.so[7f605152d000+2000]

Just to name some. But the message 
Mär 10 07:53:58 XPS7590 pipewire[3594]: protocol-native 0x55f127fe3ca0: client 0x55f127ffb420 error -9 (Bad file descriptor)
always preceded.

However "systemctl --user stop pipewire.service; systemctl --user stop pipewire.socket;" guaranteed to crash kwin. 

"Too many files open" should not be the problem. I've incrased it to 999999999 and I'm still able to produce a crash with some clicks.

Since I'm stuck with two 4K panels there's no way to change back to X11 unfortunately.
Comment 7 mikro 2021-03-16 18:54:11 UTC
I am on Fedora and I have currently installed (using a Copr repo) plasma 5.21.2.

Kwin_wayland crashes, like 5 times a day. Almost every time after a crash, restarts and I am back to my plasma session minus all the apps that I had opened before the crash.

Checking the logs, most of the time, I see just a few seconds before kwin crashes, the following error from pipewire:

mempool 0x564e73962600: Failed to create memfd: Too many open files.



The log entry for kwin_wayland is the following:

kwin_wayland[16292]: segfault at 7ff5bc171bd0 ip 00007ff5bc171bd0 sp 00007ffccf19b1a0 error 14 in wayland.mozilla.ipc.15 (deleted)[7ff5bc1a1000+44000]



Below I am copying the relevant part from the output of coredumpctl from my last crash:

Tue 2021-03-16 20:18:05 EET   16292  1000  1000  11 truncated /usr/bin/kwin_wayland
Tue 2021-03-16 20:18:13 EET   32154  1000  1000   6 present   /usr/libexec/baloorunner
Tue 2021-03-16 20:18:13 EET   16555  1000  1000   6 present   /usr/libexec/kactivitymanagerd
Tue 2021-03-16 20:18:13 EET   20935  1000  1000   6 present   /usr/libexec/xdg-desktop-portal-kde
Tue 2021-03-16 20:18:13 EET   16670  1000  1000   6 present   /usr/bin/python3.9
Tue 2021-03-16 20:18:13 EET   89322  1000  1000   6 present   /usr/bin/ocs-url
Tue 2021-03-16 20:18:14 EET   89205  1000  1000   6 present   /usr/bin/ocs-url
Tue 2021-03-16 20:18:14 EET   86174  1000  1000   6 present   /usr/bin/kwalletd5
Tue 2021-03-16 20:18:14 EET   25833  1000  1000   6 present   /usr/bin/konsole
Tue 2021-03-16 20:18:14 EET   89004  1000  1000   6 present   /usr/bin/kwrite
Tue 2021-03-16 20:18:14 EET   16477  1000  1000   6 present   /usr/bin/kded5
Tue 2021-03-16 20:18:14 EET   24127  1000  1000   6 present   /usr/bin/plasma-systemmonitor
Tue 2021-03-16 20:18:15 EET   25908  1000  1000   6 present   /usr/bin/krunner
Tue 2021-03-16 20:18:16 EET   86655  1000  1000   6 present   /usr/bin/plasma-discover
Tue 2021-03-16 20:18:18 EET   34816  1000  1000   6 truncated /usr/bin/plasmashell




Unfortunately the backtrace for kwin_wayland using "coredumpctl gdb 16292" does not seem usable. It gives (after I issue "bt") the following:

#0  0x00007ff5bc171bd0 in ?? ()
Backtrace stopped: Cannot access memory at address 0x7ffccf19b1a0



I thought that the above issue may has something to do with the bug reported here. Please ignore if it is not relevant.
Comment 8 Chang Liu 2021-04-04 03:20:26 UTC
I found that one can stop plasmashell before restart pipewire, then kwin will not crash.

1. kquitapp5 plasmashell
2. systemctl --user restart pipewire.service
3. kstart5 plasmashell

Seems like a plamashell issue.
Comment 9 Vlad Zahorodnii 2021-04-07 19:35:29 UTC
*** Bug 434452 has been marked as a duplicate of this bug. ***
Comment 10 Bug Janitor Service 2021-04-13 08:31:14 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/852
Comment 11 Alois Wohlschlager 2021-04-13 08:45:19 UTC
Git commit 59f6b77612d3e80fa579064ebdcccfd2127158c9 by Alois Wohlschlager.
Committed on 13/04/2021 at 08:28.
Pushed by davidedmundson into branch 'master'.

Fix crash when stopping PipeWire streaming

The stream object was deleted from a slot connected to its stopStreaming
signal. This is unsafe and can lead to memory corruption and ultimately
crashes when PipWwire streaming is stopped. Use deleteLater instead.
Related: bug 435588

M  +1    -1    src/plugins/screencast/screencastmanager.cpp

https://invent.kde.org/plasma/kwin/commit/59f6b77612d3e80fa579064ebdcccfd2127158c9
Comment 12 Aleix Pol 2021-04-18 18:50:04 UTC
Git commit 3a51749f09a95e37cc225c4c3f920925fc1de64b by Aleix Pol, on behalf of Alois Wohlschlager.
Committed on 18/04/2021 at 18:49.
Pushed by apol into branch 'Plasma/5.21'.

Fix crash when stopping PipeWire streaming

The stream object was deleted from a slot connected to its stopStreaming
signal. This is unsafe and can lead to memory corruption and ultimately
crashes when PipWwire streaming is stopped. Use deleteLater instead.
Related: bug 435588

M  +1    -1    plugins/screencast/screencastmanager.cpp

https://invent.kde.org/plasma/kwin/commit/3a51749f09a95e37cc225c4c3f920925fc1de64b
Comment 13 David Patin 2021-04-23 18:41:48 UTC
In which version of KDE Plasma this bug is fixd ? Because I'm with version 5.21.4 and I have the same bug.
Comment 14 Alois Wohlschlager 2021-04-24 09:21:25 UTC
As indicated in the "Version Fixed In" field, the fix will be included 5.22. In addition, it was backported to be part of 5.21.5.