<!DOCTYPE html>
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Package: gnome-session-bin<br>
      Version: 48.0-1+deb13u1<br>
      Severity: important<br>
      <br>
    </p>
    <p><span>During shutdown of a GNOME Wayland session, </span><code><span>gnome-session-ctl</span></code><span>
        can fail to restart the persistent user D-Bus if a
        D-Bus-activated service concurrently causes </span><code><span>xdg-desktop-portal.service</span></code><span>
        to be queued for startup.</span></p>
    <p><span>This leaves the old user-bus/portal state behind and can
        delay application startup after the following graphical login
        until D-Bus/portal activation timeouts of 120 seconds expire.</span></p>
    <p><span>I have a reproducible A/B test for the race.</span></p>
    <p><span>The affected system is Debian 13 (trixie), GNOME 48,
        Wayland. I also have persistent SSH sessions, so the systemd
        user manager and user D-Bus remain alive across graphical
        logout.</span></p>
    <p><span>In my case the trigger is a late D-Bus activation of
        Nextcloud by Firefox. This is a separate known Nextcloud issue
        and is not the bug I am reporting here; it merely provides a
        reliable way of triggering the gnome-session race.</span></p>
    <p><span>During logout, after the normal Nextcloud instance has
        already been terminated, Firefox requests:</span></p>
    <pre><code><span>com.nextcloudgmbh.Nextcloud</span></code></pre>
    <p><span>D-Bus starts:</span></p>
    <pre><code><span>/usr/bin/nextcloud --background</span></code></pre>
    <p><span>The graphical session is already being torn down, so this
        newly started Nextcloud process cannot connect to Wayland/X11.
        Before terminating, however, it requests:</span></p>
    <pre><code><span>org.freedesktop.portal.Desktop</span></code></pre>
    <p><span>This queues </span><code><span>xdg-desktop-portal.service</span></code><span>
        for startup just as GNOME runs </span><code><span>gnome-session-restart-dbus.service</span></code><span>.</span></p>
    <p><span>The journal then shows:</span></p>
    <pre><code><span>systemd: Starting xdg-desktop-portal.service - Portal service...

systemd: Starting gnome-session-restart-dbus.service
         - Restart DBus after GNOME Session shutdown...

systemd: Requested transaction contradicts existing jobs:
         Transaction for dbus.service/stop is destructive
         (xdg-desktop-portal.service has 'start' job queued,
         but 'stop' is included in transaction).

gnome-session-ctl: Failed to restart DBus service:
         GDBus.Error:org.freedesktop.systemd1.TransactionIsDestructive:
         Transaction for dbus.service/stop is destructive
         (xdg-desktop-portal.service has 'start' job queued,
         but 'stop' is included in transaction).</span></code></pre>
    <p><span>At this point </span><code><span>graphical-session.target</span></code><span>
        is already inactive. The newly started portal attempts to
        activate the GNOME portal backend, which consequently fails its
        dependency.</span></p>
    <p><span>The graphical logout itself completes. However, the
        intended restart of the user D-Bus has failed.</span></p>
    <p><span>After the next graphical login, portal activation becomes
        stuck. The journal subsequently shows errors including:</span></p>
    <pre><code><span>Error calling StartServiceByName for
    org.freedesktop.portal.Desktop:
    Timeout was reached</span></code></pre>
    <p><span>and:</span></p>
    <pre><code><span>xdg-desktop-portal.service:
    start operation timed out. Terminating.</span></code></pre>
    <p><span>Eventually D-Bus reports activation timeouts with:</span></p>
    <pre><code><span>service_start_timeout=120000ms</span></code></pre>
    <p><span>During this interval applications launched from the desktop
        appear not to start. They eventually appear together after the
        timeout/race has resolved.</span></p>
    <p><span>I can prevent the triggering activation without otherwise
        changing the session by installing this per-user D-Bus override:</span></p>
    <pre><code><span>~/.local/share/dbus-1/services/com.nextcloudgmbh.Nextcloud.service</span></code></pre>
    <p><span>containing:</span></p>
    <pre><code><span><span>[D-BUS Service]</span>
Name=com.nextcloudgmbh.Nextcloud
Exec=/bin/false</span></code></pre>
    <p><span>This provides a reproducible A/B test.</span></p>
    <p><span>With the override installed, Firefox makes exactly the same
        request for </span><code><span>com.nextcloudgmbh.Nextcloud</span></code><span>
        during logout, but activation fails immediately.</span></p>
    <p><span>The journal then shows, in the same second:</span></p>
    <pre><code><span>Activated service 'com.nextcloudgmbh.Nextcloud' failed:
    Process com.nextcloudgmbh.Nextcloud exited with status 1

Starting gnome-session-restart-dbus.service
    - Restart DBus after GNOME Session shutdown...

Started gnome-session-restart-dbus.service
    - Restart DBus after GNOME Session shutdown.

Stopping dbus.service - D-Bus User Message Bus...

Stopped dbus.service - D-Bus User Message Bus.</span></code></pre>
    <p><span>The following login is immediate.</span></p>
    <p><span>Nextcloud is then started normally by GNOME autostart. It
        requests </span><code><span>org.freedesktop.portal.Desktop</span></code><span>,
        and the portal services start normally within approximately one
        second.</span></p>
    <p><span>I repeated this test, including deliberately waiting until
        a Nextcloud desktop notification appeared before launching
        applications. Application startup remained immediate. Thus the
        notifications are unrelated to the delay.</span></p>
    <p>The Nextcloud D-Bus activation problem has separately been
      reported as a follow-up to Debian bug #1072382 and upstream in
      Nextcloud Desktop issue #7653<span>. It is not necessary for this
        gnome-session bug: any sufficiently late D-Bus activation which
        queues a service depending on </span><code><span>dbus.service</span></code><span>
        appears capable of producing the race.</span></p>
    <p><span>The problem here is that </span><code><span>gnome-session-restart-dbus.service</span></code><span>
        is specifically intended to restart the persistent user bus
        after graphical-session shutdown, but a concurrently queued
        D-Bus activation can make that restart fail with </span><code><span>TransactionIsDestructive</span></code><span>.
        The failure then leaves state from the old graphical session in
        the persistent user manager and affects the following login.</span></p>
    <p><span>I believe gnome-session should ensure that the intended
        D-Bus restart completes even when another D-Bus activation races
        with session shutdown. At minimum, </span><code><span>TransactionIsDestructive</span></code><span>
        should not cause the restart to be abandoned without recovery.</span></p>
    <p><span>Relevant versions:</span></p>
    <pre><code><span>gnome-session-bin           48.0-1+deb13u1
gnome-session-common        48.0-1+deb13u1
systemd                     257.13-1~deb13u1
dbus-user-session           1.16.2-2
firefox-esr                 140.16.0esr-1~deb13u1
nextcloud-desktop           3.16.7-1~deb13u1
xdg-desktop-portal          1.22.1+ds-1~bpo13+1
xdg-desktop-portal-gnome    48.0-2
fuse3                       3.18.3-1~bpo13+1
libfuse3-4                  3.18.3-1~bpo13+1</span></code></pre>
    <p><code><span>xdg-desktop-portal</span></code><span> 1.22.1 and
        FUSE 3.18.3 are local backports built from Debian testing source
        on Debian 13. I installed them while investigating an earlier,
        separate </span><code><span>xdg-document-portal</span></code><span>
        shutdown problem.</span></p>
    <p><span>The D-Bus restart race described above occurred after those
        newer versions were already installed. In particular, </span><code><span>xdg-document-portal</span></code><span>
        itself stopped and started promptly in the tests described here.</span></p>
    <p><span>The affected computer is older hardware (from 2018), but
        otherwise performs normally. The observed delay is not general
        system slowness: it corresponds to explicit 120-second service
        activation timeouts and disappears completely in the A/B test
        above.</span></p>
    <p><br>
    </p>
  </body>
</html>