The greeter that would not die
TL;DR: After an idle lock dismissed with the mouse, later locks on my Tumbleweed workstation came up as a black screen with only the cursor. The lock screen process had hung, most likely in the NVIDIA driver, and a race in KDE's kscreenlocker turned that into a locked session with nothing to type a password into. The race reproduces in a VM without NVIDIA. My Hack Week 26 project ended with two merge requests: kscreenlocker!401 fixes the race, kscreenlocker!402 fixes a file descriptor leak found on the way. The leak fix is merged and will ship in Plasma 6.8.5. The race fix is in review.
What was wrong
Lock the screen, come back, black screen. The cursor moves, there is no password field, and only a VT gets you out. I reported it in November as bug 528681. A second reporter sees the same on a GTX 1050 Ti.
Plasma's lock screen is two processes. KSldApp runs inside kwin and decides
when to lock. The greeter, kscreenlocker_greet, draws the password field.
With a grace time set, an idle lock can be dismissed without a password by
moving the mouse. In kscreenlocker 6.8.3 that path is:
void KSldApp::unlock()
{
qCDebug(KSCREENLOCKER) << "Unlock requested";
if (isGraceTime() || !m_requirePassword) {
// the process might take some time to exit; don't wait for that to happen
doUnlock();
s_graceTimeKill = true;
m_lockProcess->terminate();
}
}
The session unlocks at once and the greeter only gets a SIGTERM. That is on
purpose since 2024: waiting for the greeter only delayed the unlock. But if the
greeter is still alive when the next lock comes, KSldApp calls
QProcess::start() on the same running process. Qt prints
QProcess::start: Process is already running, reports no error, and the
session stays locked without a greeter.
How I found it
My journal has two stuck greeters, on 30 October and 10 November. Both went silent less than half a second after they started, while their PAM worker was still starting, and never logged anything again. Why they ignored the SIGTERM is not proven: I recovered the session before taking a backtrace. The one I inspected had all threads asleep, with under a second of CPU time in two hours. The likeliest cause is the NVIDIA EGL stack (Pascal card, driver 580.196.07): egl-wayland#208 reports the same driver hanging plasmashell inside EGL.
kill -STOP on the greeter has the same effect as a hang. In a Tumbleweed VM
with Plasma 6.8.3: lock with a grace time, stop the greeter, move the mouse,
lock again. Black screen, every time. The script is attached to the bug.
The stop is not even needed. A lock that comes before kwin has noticed the old greeter's exit hits the same code. Locking again as soon as the session reported unlocked broke 2 of 11 tries on stock 6.8.3. The window is a few tens of milliseconds, so in real use it takes a hung greeter.
One stock run went further. The s_graceTimeKill flag from the grace unlock
was still set, so KSldApp treated the next greeter's crash as expected and did
not restart it. A loginctl lock-session in that state sent SIGUSR1 to process
ID 0, which means kwin's whole process group. kwin died and took the session
with it.
The fix
kscreenlocker!401 replaces a greeter process that is still running with a new
QProcess before starting the next greeter. The old one is killed without
waiting, because this code runs inside the compositor. The exit flags are reset
for every greeter, and lock() no longer signals pid 0. An earlier merge
request, !289,
had the same idea and was closed without being merged.
While testing I counted kwin's file descriptors: two more after every lock.
kwin hands KSldApp a socket for the greeter's Wayland connection, KSldApp gave
the greeter a dup() of it, and neither was ever closed. ss -xp showed every dead socket held twice by kwin. After review by
Vlad Zahorodnii, kscreenlocker!402 lets the greeter inherit the socket itself
instead of a copy, and makes KSldApp own it, so kwin needs no change.
Vlad merged !402 the same day, and the backport to Plasma 6.8,
!403,
right after. !401 is in review. The project page also promised an openQA
test. I left it out: the real trigger is a hung greeter, and a kill -STOP
test would only soft-fail on every run.
Result
| Before | After | |
|---|---|---|
| Lock after a stuck grace greeter | black screen, cursor only | lock screen, stuck greeter killed |
| Fast relock after a grace unlock | 2 of 11 broken | 0 of 20 broken |
| kwin file descriptors per lock | +2 | 0 |
Not tested: locking before suspend, because both S3 and s2idle hang the test VM
on resume. That path goes through the same lock() call as the logind lock,
which was tested. On the NVIDIA side, I switched to egl-wayland2 for another
reason and have not seen the hang since, but LockGrace=0 has been set the
whole time, so the grace path never ran.
Until the fix lands, LockGrace=0 avoids the bug. If the screen is already
black, kill the greeter with kill -9 first, then run
loginctl unlock-session. In the other order, the unlock only sends another
SIGTERM to a greeter that ignores it.
How this was made
AI help: an AI agent correlated the journal entries of the stuck greeters,
drove the test VM over QMP, and ran the before/after loops and the descriptor
counts.
Code: reviewed line by line by me, like any other patch, and checked in the VM
runs.