plasma-shutdown: Guard against concurrent logout/reboot/shutdown requests

Original commit message(s)

  • plasma-shutdown: Guard against concurrent logout/reboot/shutdown requests

A second, overlapping call to logout()/logoutAndShutdown()/logoutAndReboot() while one is already in progress starts a duplicate startLogout() flow in the same process. Both flows eventually call KWin's SessionManager::closeWaylandWindows(), which correctly rejects the second, overlapping call with "Operation already in progress". That rejection is currently treated as fatal: Shutdown::ksmServerComplete() reacts to it by calling resetLogout() and logoutCancelled(), which calls qApp->quit() and tears down the whole plasma-shutdown process - including the first, legitimate request that was still in flight and would very plausibly have completed successfully on its own.

In practice this can be triggered by a client issuing the D-Bus call twice in quick succession (e.g. observed with Discover's "Reboot after update" firing org.kde.Shutdown.logoutAndReboot twice, ~400 microseconds apart, due to a QML state re-entry issue). The user ends up with all applications closed but the session never actually logging out or rebooting.

This adds a simple re-entrancy guard: a second concurrent request is ignored (logged and returned early) instead of racing a duplicate flow against the first one. Confirmed against a live reproduction: deliberately issuing logoutAndReboot() twice in rapid succession, which reliably reproduced the crash before this change, now completes the first request cleanly with no collision.

BUG: 525911

Reason for the change

A second, overlapping D-Bus call to logout()/logoutAndShutdown()/logoutAndReboot() while one is already in progress starts a duplicate startLogout() flow in the same plasma-shutdown process. Both flows eventually call KWin's SessionManager::closeWaylandWindows(), which correctly rejects the second, overlapping call with "Operation already in progress". That rejection is currently treated as fatal: Shutdown::ksmServerComplete() reacts to it by calling resetLogout() and logoutCancelled(), which calls qApp->quit() and tears down the entire plasma-shutdown process — including the first, legitimate request that was still in flight and would very plausibly have completed successfully on its own.

In practice this is triggered by Discover's "Reboot after update" option, which can fire org.kde.Shutdown.logoutAndReboot twice in quick succession (a QML state re-entry issue in discover, tracked separately). The user ends up with all applications closed, but the session never actually logs out or reboots — see bug 525911 for the full reproduction and D-Bus wire trace.

The correct fix belongs in more than one place long-term (Discover shouldn't fire the request twice in the first place, and KWin's rejection arguably shouldn't be fatal to the whole caller process either), but this is the most direct, minimal fix: a second concurrent request should simply be ignored rather than racing a duplicate flow against the first one and taking it down as collateral damage.

Test plan

There's no existing automated test coverage for plasma-shutdown's D-Bus-driven logout flow (it depends on ksmserver/KWin being live over D-Bus), so this was verified manually against a live reproduction:

  1. Built this patch against the exact Fedora 6.7.5 source and installed it locally.

  2. Deliberately reproduced the race by issuing the D-Bus call twice in rapid succession:

      busctl --user call org.kde.Shutdown /Shutdown org.kde.Shutdown logoutAndReboot
      busctl --user call org.kde.Shutdown /Shutdown org.kde.Shutdown logoutAndReboot
  3. Before this change: reliably reproduced the crash — "KWin failed to complete logout", session left in a broken state, no reboot.

  4. After this change: the second call is logged and ignored ("Logout already in progress, ignoring duplicate request"), the first call proceeds through closeSession → closeWaylandWindows → logoutComplete normally, and the machine reboots successfully — confirmed via journal trace showing a clean Reached target shutdown.target - Shutdown. with no collision.

A reviewer can reproduce this with the same two busctl calls above (note: the second call is a no-op either way now, so this is safe to run — the worst case if something regressed is the same pre-existing failure mode, not something new).

Screenshots or screen recordings

N/A — no visual/UI change.

Bugs fixed

BUG: 525911

Edited by Gregor Papez

Merge request reports

Loading
Loading