Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow startup due to deadlock if o.fd.FileManager1 is implemented by GtkApplication #636

Closed
minhduc0711 opened this issue Sep 24, 2021 · 11 comments · Fixed by #639
Closed

Comments

@minhduc0711
Copy link

minhduc0711 commented Sep 24, 2021

As a result, several apps have to wait while the service was starting.

This starts happening when I updated to 1.10.1. Notice the time between the Starting Portal service and Started Portal service:

● xdg-desktop-portal.service - Portal service
     Loaded: loaded (/usr/lib/systemd/user/xdg-desktop-portal.service; static)
     Active: active (running) since Fri 2021-09-24 10:24:12 +07; 46s ago
   Main PID: 31907 (xdg-desktop-por)
      Tasks: 10 (limit: 23842)
     Memory: 3.7M
        CPU: 392ms
     CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/xdg-desktop-portal.service
             └─31907 /usr/lib/xdg-desktop-portal

Sep 24 10:23:47 acer-aspire-a5 systemd[924]: Starting Portal service...
Sep 24 10:24:12 acer-aspire-a5 systemd[924]: Started Portal service.
Sep 24 10:24:42 acer-aspire-a5 xdg-desktop-por[31907]: Failed to get application states: GDBus.Error:org.freedesktop.portal.Error.Failed: Could not get window list

The service started immediately in 1.8.1:

● xdg-desktop-portal.service - Portal service
     Loaded: loaded (/usr/lib/systemd/user/xdg-desktop-portal.service; static)
     Active: active (running) since Fri 2021-09-24 10:26:46 +07; 1s ago
   Main PID: 34405 (xdg-desktop-por)
      Tasks: 8 (limit: 23842)
     Memory: 3.1M
        CPU: 101ms
     CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/xdg-desktop-portal.service
             └─34405 /usr/lib/xdg-desktop-portal

Sep 24 10:26:46 acer-aspire-a5 systemd[924]: Starting Portal service...
Sep 24 10:26:46 acer-aspire-a5 systemd[924]: Started Portal service.                                                    

FYI I also use sway, so there might be some configuration problems.
Edit: I checked #607, but my xdg-desktop-portal-wlr seems to start up properly.

@AidanGG
Copy link

AidanGG commented Sep 25, 2021

Do you happen to use xdg-desktop-portal-gtk and some GTK-based file manager? Perhaps the Reddit thread here might be similar to your issue: https://www.reddit.com/r/swaywm/comments/ptwd6p/thunar_and_xdgdesktopportal_block_each_other/

@minhduc0711
Copy link
Author

Thank you, I removed xdg-desktop-portal-gtk and the issue is gone. I will just gonna leave this issue open for now in case it's a bug in xdg-desktop-portal.

@smcv smcv changed the title xdg-desktop-portal service starts up slowly Slow startup due to deadlock if o.fd.FileManager1 is implemented by GtkApplication Sep 30, 2021
@smcv
Copy link
Collaborator

smcv commented Sep 30, 2021

Do you happen to use [...] some GTK-based file manager?

This issue was also reported in Debian, and from debug information provided by the bug reporter, this is the key factor.

The problem is that xdg-desktop-portal calls into org.freedesktop.FileManager1 on startup (to find out whether it can be used to implement the OpenURI interface), and GTK's GtkApplication class (as used in e.g. Thunar) calls into the Inhibit portal on startup (to use it as a desktop-neutral way to offer an interface to inhinit screensaver/suspend/shutdown). This would be fine if they both used asynchronous D-Bus calls and continued to start up without waiting for a result, but they don't: they both use synchronous (blocking) D-Bus calls. This means neither one will successfully start up until it gets a reply from the other, causing a deadlock. The dbus-daemon waits for an arbitrary length of time for the two services to start up, then resolves the deadlock by deciding that service-activation is taking too long and sending an error reply.

This will only happen in non-GNOME environments. If gnome-session is running, GTK bypasses the Inhibit portal abstraction and uses gnome-session's D-Bus interfaces directly, so this will not occur.

I removed xdg-desktop-portal-gtk and the issue is gone. I will just gonna leave this issue open for now in case it's a bug in xdg-desktop-portal.

It's a bug in xdg-desktop-portal (and/or GTK, but I think it's going to be a lot easier to fix here than in GTK). Removing the -gtk backend probably only works around this by coincidence, because the -gtk backend provides the AppChooser interface (which is required for OpenURI) and the -wlr backend does not.

xdg-desktop-portal will not have full functionality without an implementation of the AppChooser interface.

@smcv
Copy link
Collaborator

smcv commented Sep 30, 2021

This appears to have regressed in #601, while fixing #564.

@smcv
Copy link
Collaborator

smcv commented Sep 30, 2021

This will only happen in non-GNOME environments

After wasting some time trying to reproduce this in XFCE, make that "non-GNOME && non-XFCE environments"... (GTK has specific support for XFCE's session manager, too.)

smcv added a commit to smcv/xdg-desktop-portal that referenced this issue Sep 30, 2021
Making a synchronous call into a GTK implementation of o.fd.FileManager1
can cause a deadlock, because GtkApplication makes a synchronous call
into the Inhibit portal when started in a non-GNOME, non-XFCE environment.
In this situation, each service does not take its bus name (and hence
complete service-activation) until it gets a reply from the other, which
obviously can't work.

We don't actually need a GDBusProxy here: we don't need to subscribe to
any signals, watch any properties or hold any state, so it's just as
straightforward to use g_dbus_connection_call_sync() on a just-in-time
basis.

Fixes: 69961f3 "openuri: Use FileManager1 in OpenDirectory"
Resolves: flatpak#636
Signed-off-by: Simon McVittie <[email protected]>
smcv added a commit to smcv/xdg-desktop-portal that referenced this issue Oct 5, 2021
Making a synchronous call into a GTK implementation of o.fd.FileManager1
can cause a deadlock, because GtkApplication makes a synchronous call
into the Inhibit portal when started in a non-GNOME, non-XFCE environment.
In this situation, each service does not take its bus name (and hence
complete service-activation) until it gets a reply from the other, which
obviously can't work.

We don't actually need a GDBusProxy here: we don't need to subscribe to
any signals, watch any properties or hold any state, so it's just as
straightforward to use g_dbus_connection_call_sync() on a just-in-time
basis.

The indentation is deliberately a bit odd here, to avoid a large
diffstat from re-indentation; it will be fixed in a subsequent commit.

Fixes: 69961f3 "openuri: Use FileManager1 in OpenDirectory"
Resolves: flatpak#636
Signed-off-by: Simon McVittie <[email protected]>
alexlarsson pushed a commit that referenced this issue Oct 6, 2021
Making a synchronous call into a GTK implementation of o.fd.FileManager1
can cause a deadlock, because GtkApplication makes a synchronous call
into the Inhibit portal when started in a non-GNOME, non-XFCE environment.
In this situation, each service does not take its bus name (and hence
complete service-activation) until it gets a reply from the other, which
obviously can't work.

We don't actually need a GDBusProxy here: we don't need to subscribe to
any signals, watch any properties or hold any state, so it's just as
straightforward to use g_dbus_connection_call_sync() on a just-in-time
basis.

The indentation is deliberately a bit odd here, to avoid a large
diffstat from re-indentation; it will be fixed in a subsequent commit.

Fixes: 69961f3 "openuri: Use FileManager1 in OpenDirectory"
Resolves: #636
Signed-off-by: Simon McVittie <[email protected]>
@languitar
Copy link

Any chance to push out a new release including this fix?

@pietryszak
Copy link

Any chance to push out a new release including this fix?

Why new version with this fix is not released yet ?

3v1n0 pushed a commit to 3v1n0/xdg-desktop-portal that referenced this issue Nov 17, 2021
Making a synchronous call into a GTK implementation of o.fd.FileManager1
can cause a deadlock, because GtkApplication makes a synchronous call
into the Inhibit portal when started in a non-GNOME, non-XFCE environment.
In this situation, each service does not take its bus name (and hence
complete service-activation) until it gets a reply from the other, which
obviously can't work.

We don't actually need a GDBusProxy here: we don't need to subscribe to
any signals, watch any properties or hold any state, so it's just as
straightforward to use g_dbus_connection_call_sync() on a just-in-time
basis.

The indentation is deliberately a bit odd here, to avoid a large
diffstat from re-indentation; it will be fixed in a subsequent commit.

Fixes: 69961f3 "openuri: Use FileManager1 in OpenDirectory"
Resolves: flatpak#636
Signed-off-by: Simon McVittie <[email protected]>
@WhyNotHugo
Copy link
Contributor

Can a new release with this fix be pushed out? This adds an artificial delay at system startup that's very annoying.

3v1n0 pushed a commit to 3v1n0/xdg-desktop-portal that referenced this issue Jan 11, 2022
Making a synchronous call into a GTK implementation of o.fd.FileManager1
can cause a deadlock, because GtkApplication makes a synchronous call
into the Inhibit portal when started in a non-GNOME, non-XFCE environment.
In this situation, each service does not take its bus name (and hence
complete service-activation) until it gets a reply from the other, which
obviously can't work.

We don't actually need a GDBusProxy here: we don't need to subscribe to
any signals, watch any properties or hold any state, so it's just as
straightforward to use g_dbus_connection_call_sync() on a just-in-time
basis.

The indentation is deliberately a bit odd here, to avoid a large
diffstat from re-indentation; it will be fixed in a subsequent commit.

Fixes: 69961f3 "openuri: Use FileManager1 in OpenDirectory"
Resolves: flatpak#636
Signed-off-by: Simon McVittie <[email protected]>
@Mahrjose
Copy link

Is this fixed yet? I'm having similar problem. Installing flatpak package in arch linux (xmonad) slows down thunar startup time by 25-30s! Without flatpak installed startup time is only 2-3s.

@hyuri
Copy link

hyuri commented Sep 5, 2023

Still happening. Chromium flatpak takes 5 minutes to open after startup.

Pop!_OS 22.04 (Gnome 42.9)

@smcv
Copy link
Collaborator

smcv commented Sep 5, 2023

#639 was included in 1.12.0 and all newer versions.

@Mahrjose, @hyuri, you might be experiencing the same issue as #986 and #1024, rather than what was originally reported here. If so, xdg-desktop-portal 1.17.0 should resolve that.

If you are experiencing a similar symptom with xdg-desktop-portal 1.17.0 or later, please open a separate issue with more information, such as the versions of relevant components that you are using (xdg-desktop-portal, any backends such as xdg-desktop-portal-gtk that you have installed) and the messages that appear in the systemd journal during the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants