Bug 398654

Summary: QT_QPA_PLATFORM, unset by default, defaults to xcb, causing Xwayland to segfault due to not being able to handle Plasma Shell
Product: [Plasma] plasmashell Reporter: Kyle Devir <kyle.devir>
Component: generic-crashAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: normal CC: arojas
Priority: NOR    
Version First Reported In: 5.13.90   
Target Milestone: 1.0   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Kyle Devir 2018-09-15 07:47:16 UTC
I discovered that because QT_QPA_PLATFORM is unset by default, Qt 5.11.1 defaults it to xcb, meaning that when kwin_wayland starts /usr/lib/startplasma via startplasmacompositor, Plasma Shell runs on Xwayland.

Xwayland can't seem to handle Plasma Shell, causing Xwayland to segfault in short order.

If I add QT_QPA_BACKEND=wayland to the startplasmacompositor script, Plasma Shell never crashes under any circumstances.

I've heard that Qt5 was supposed to sort out QT_QPA_BACKEND automatically by giving each application what it prefers, however, either it's not working out in practice, or this is something that's coming in a later major release.
Comment 1 Antonio Rojas 2018-09-15 07:52:12 UTC
Which distro?
Comment 2 Kyle Devir 2018-09-15 07:58:42 UTC
Arch Linux.
Comment 3 Antonio Rojas 2018-09-15 08:24:14 UTC
It works fine here. How do you know that plasmashell is running on xwayland?
Comment 4 Kyle Devir 2018-09-15 08:56:06 UTC
Because with "QT_QPA_PLATFORM=wayland" added, Xwayland never once segfaults, at all, no matter what I do with Plasma Shell. Every single time I've started Plasma Shell like this, it just works. It runs for hours, quite happily.

With "QT_QPA_PLATFORM=xcb", however, Xwayland segfaults almost immediately, freezing kwin_wayland, exactly like the vanilla startplasmacompositor script does. When I reboot via SysRQ REISUB, because I can't even switch TTYs at that point, journalctl shows Xwayland segfaulting.

So, that made me suspicious that QT_QPA_PLATFORM was defaulting to XCB for some odd reason. My experimentation makes me quite certain that this is the case.
Comment 5 Kyle Devir 2018-09-15 09:00:15 UTC
I probably should have specified at the beginning that I'm running an RX580 with Mesa master and LLVM master from AUR.

I'm not sure this has an impact, because with QT_QPA_PLATFORM=wayland, there's no freezing.

It seems like a possible Xwayland problem, if it can't even handle full Plasma Shell under kwin_wayland.
Comment 6 Antonio Rojas 2018-09-15 09:06:51 UTC
Try this: from a X Plasma session, run a nested kwin_wayland:
$ kwin_wayland --xwayland

Then from a terminal kill the plasmashell process and run
$ XDG_SESSION_TYPE=wayland plasmashell

Does Plasma open in the nested Wayland window?
Comment 7 Kyle Devir 2018-09-15 09:33:18 UTC
No, it doesn't.

It just exits immediately, because of the already running plasmashell process.
Comment 8 Antonio Rojas 2018-09-15 09:46:43 UTC
(In reply to Kyle Devir from comment #7)
> No, it doesn't.
> 
> It just exits immediately, because of the already running plasmashell
> process.

That's why I said "kill the plasmashell process"
Comment 9 Kyle Devir 2018-09-15 09:54:56 UTC
Whoops. I skipped that part somehow. Let's try that again...
Comment 10 Kyle Devir 2018-09-15 10:02:17 UTC
Now that I've done it properly...

Yes, it works just fine. Also, Xwayland doesn't segfault at all, amusingly.

What next, I wonder?
Comment 11 Antonio Rojas 2018-09-15 10:03:48 UTC
That means that the Qt platform detection code is working correctly, so your problem is somewhere else. 

When you log into Plasma Wayland, what is XDG_SESSION_TYPE set to? How are you logging in?
Comment 12 Kyle Devir 2018-09-15 10:22:51 UTC
XDG_SESSION_TYPE is unset.

I log in via TTY, and then run startplasmacompositor.

Does KDE rely on a GUI login manager to set XDG_SESSION_TYPE properly...?
Comment 13 Antonio Rojas 2018-09-15 10:25:12 UTC
Qt (and plasma-workspace's own code) rely on the XDG_SESSION_TYPE environment variable to choose the correct QPA platform. Display managers will automatically set it for you, if you don't use one then it's your job to make sure it's correctly set.
Comment 14 Kyle Devir 2018-09-15 10:26:46 UTC
Ah.

That explains my woes. Damn it. :/

Thanks Antonio! :)