Bug 31855

Summary: Long delay when starting other DEs/applications in a multi-DE installation that includes GNOME
Product: Mageia Reporter: Martin Whitaker <mageia>
Component: RPM PackagesAssignee: All Packagers <pkg-bugs>
Status: NEW --- QA Contact:
Severity: normal    
Priority: Normal CC: ghibomgx, yvesbrungard
Version: Cauldron   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Source RPM: xdg-desktop-portal, xdg-desktop-portal-gnome CVE:
Status comment:
Attachments: patch to import XDG_SESSION_DESKTOP

Description Martin Whitaker 2023-05-01 16:47:29 CEST
To reproduce, perform a fresh install that includes both GNOME and Xfce. When you log in to an Xfce session, there is a ~50s delay before the desktop appears.

The culprit is the xdg-desktop-portal-gnome service, which is automatically started by the xdg-desktop-portal service. The xdg-desktop-portal-gnome service depends on the graphical-session target, but that target is only enabled in Plasma and GNOME sessions. The xdg-desktop-portal-gnome service fails immediately, but it is started via dbus, and it appears that dbus doesn't report the error back to the requester immediately but instead relies on a timeout (which defaults to 50s).

For some other DEs, e.g. Cinnamon, there is no delay on logging in but there is a delay when you start an application, e.g. Firefox, that triggers the xdg-desktop-portal service.
Comment 1 Martin Whitaker 2023-05-01 18:35:59 CEST
I've implemented a fix for this, by adding support for an OnlyIn key in the backend portal descriptor files and adding that key in the gnome.portal file. This stops xdg-desktop-portal from using the gnome backend when XDG_CURRENT_DESKTOP does not include GNOME.

Assignee: bugsquad => mageia
Source RPM: (none) => xdg-desktop-portal, xdg-desktop-portal-gnome

Comment 2 Martin Whitaker 2023-05-03 18:48:14 CEST
Further testing shows my fix isn't totally robust. Depending on the DM being used and the DE being logged into, the XDG_CURRENT_DESKTOP environment variable in the systemd user session may or may not get updated before the xdg-desktop-portal service is started. I haven't found a way to fix that, other than either rebooting between sessions or manually killing the 'systemd --user' process between sessions.

As a temporary fix, gnome-shell has been changed to recommend rather than require xdg-desktop-portal-gnome.

To reproduce the problem now:

1. Do a clean GNOME-only install.
2. Log into a GNOME session.
3. Install the xdg-desktop-portal-gnome package.
4. Execute 'systemctl --user restart xdg-desktop-portal'.
5. Log out.
6. Log into an IceWM session.
7. Start Firefox and observe the long startup delay.
8. Also observe the following:

  $ echo $XDG_CURRENT_DESKTOP
  ICEWM
  $ systemctl --user show-environment | grep XDG_CURRENT_DESKTOP
  XDG_CURRENT_DESKTOP=GNOME

The same behaviour can be observed when using GDM or LightDM.

With other DEs the systemd user session environment may get updated by the time the desktop is displayed (so 'systemctl --user show-environment' shows the correct DE name), but that may or may not have happened before the xdg-desktop portal service is started. This can be observed by adding the '-v' option to '/usr/libexec/xdg-desktop-portal' in /usr/lib/systemd/user/xdg-desktop-portal.service, rebooting so that it takes effect, and looking for a message like this in the system journal:

  xdg-desktop-portal[2601]: XDP: portal implementation is only for gnome; checking against GNOME

Reassigning globally.

Assignee: mageia => pkg-bugs

Comment 3 Giuseppe Ghibò 2023-05-03 19:50:48 CEST
(In reply to Martin Whitaker from comment #2)
> Further testing shows my fix isn't totally robust. Depending on the DM being
> used and the DE being logged into, the XDG_CURRENT_DESKTOP environment
> variable in the systemd user session may or may not get updated before the
> xdg-desktop-portal service is started. I haven't found a way to fix that,
> other than either rebooting between sessions or manually killing the
> 'systemd --user' process between sessions.
> 
> As a temporary fix, gnome-shell has been changed to recommend rather than
> require xdg-desktop-portal-gnome.
> 
> To reproduce the problem now:
> 
> 1. Do a clean GNOME-only install.
> 2. Log into a GNOME session.
> 3. Install the xdg-desktop-portal-gnome package.
> 4. Execute 'systemctl --user restart xdg-desktop-portal'.
> 5. Log out.
> 6. Log into an IceWM session.
> 7. Start Firefox and observe the long startup delay.
> 8. Also observe the following:
> 
>   $ echo $XDG_CURRENT_DESKTOP
>   ICEWM
>   $ systemctl --user show-environment | grep XDG_CURRENT_DESKTOP
>   XDG_CURRENT_DESKTOP=GNOME
> 
> The same behaviour can be observed when using GDM or LightDM.
> 
> With other DEs the systemd user session environment may get updated by the
> time the desktop is displayed (so 'systemctl --user show-environment' shows
> the correct DE name), but that may or may not have happened before the
> xdg-desktop portal service is started. This can be observed by adding the
> '-v' option to '/usr/libexec/xdg-desktop-portal' in
> /usr/lib/systemd/user/xdg-desktop-portal.service, rebooting so that it takes
> effect, and looking for a message like this in the system journal:
> 
>   xdg-desktop-portal[2601]: XDP: portal implementation is only for gnome;
> checking against GNOME
> 
> Reassigning globally.

Apparently there is a mismatch between the XDG_CURRENT_DESKTOP and the environment in systemd. We might try to modify the init script 50-systemd-user.sh to also import the XDG_CURRENT_DESKTOP and XDG_SESSION_DESKTOP env var.

CC: (none) => ghibomgx

Comment 4 Giuseppe Ghibò 2023-05-03 19:52:12 CEST
Created attachment 13801 [details]
patch to import XDG_SESSION_DESKTOP

patch to modify /etc/X11/xinit/xinitrc.d/50-systemd-user.sh
Comment 5 Giuseppe Ghibò 2023-05-03 21:01:33 CEST
(In reply to Giuseppe Ghibò from comment #4)

> Created attachment 13801 [details]
> patch to import XDG_SESSION_DESKTOP
> 
> patch to modify /etc/X11/xinit/xinitrc.d/50-systemd-user.sh

This works on XFCE but not on icewm. Or to be precise in icewm there is a 30 seconds delay only the first time. I wonder whether icewm is broken itself (by another problem?). On the other hand in icewm I get a 30 second delay (but only the first time after the desktop login) even when in the toolbar on the "terminal" icon, this even before the xdg-desktop-portal problems.
Comment 6 Giuseppe Ghibò 2023-05-04 18:52:35 CEST
What is weird is that sometimes (it doesn't happen all the times) there are timeouts even under GNOME itself when just doing:

systemctl --user restart xdg-desktop-portal

xdg-desktop-por[8551]: Failed to create settings proxy: Error calling StartServiceByName for org.freedesktop.impl.portal.desktop.gtk: Timeout was reached
Comment 7 papoteur 2023-11-17 12:38:20 CET
A user reported a similar problem :
https://www.mageialinux-online.org/forum/topic.php?id=31124&pt=1#m318557

There is also a discussion here:
https://github.com/flatpak/xdg-desktop-portal/issues/986

which cites a potential fix: 
https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/merge_requests/78

CC: (none) => yvesbrungard