Bug 436453 - No reply to Quit() after Inhibit() call
Summary: No reply to Quit() after Inhibit() call
Status: RESOLVED FIXED
Alias: None
Product: xdg-desktop-portal-kde
Classification: Plasma
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Manjaro Linux
: NOR normal
Target Milestone: ---
Assignee: Jan Grulich
URL:
Keywords: efficiency-and-performance
Depends on:
Blocks:
 
Reported: 2021-05-01 14:07 UTC by Carlo
Modified: 2021-09-29 23:02 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.23
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carlo 2021-05-01 14:07:31 UTC
SUMMARY
Portal documentation (https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-org.freedesktop.portal.Inhibit) prescribe that in order to remove the inhibition, the client must call Close() on the returned handle.
After a quick look at src/inhibit.cpp (and comparing it to xdg-desktop-portal-gtk) I am pretty sure no reply is prepared. This means that the client hangs on and finally crashes.

STEPS TO REPRODUCE
1. run /lib/xdg-desktop-portal-kde --verbose
2. run my quick demo: https://gist.github.com/carlocastoldi/b52a3434c36b8bf185afe4a545ff90d8
3. click on the GUI bottom twice. One for inhibiting and one for stopping the inhibition
4. make sure the Close() call is received by xdg-desktop-portal-kde
5. Wait for a certain amount of seconds

Make sure to run my demo on X11, as on Wayland I take advantage of xdg-foreign to export the toplevel handle and Kwin does not yet support it (I don't even know if there is any plans to)

OBSERVED RESULT
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken

EXPECTED RESULT
The inhibition is cancelled and a reply is sent back to the application

ADDITIONAL INFORMATION
This bug report and demo is done with the goal to ease the usage of portals by host applications (and not!) as i think they can play a really important role in the interoperability between gnu/linux environments.
I'd be happy to share ideas & code with someone who sees the same potential!

For further info: https://github.com/flatpak/xdg-desktop-portal/issues/579
Comment 1 Jan Grulich 2021-05-03 06:54:38 UTC
It is implemented here [1] and it's been used by my test app here [2]. I just tested it and it works just fine.

[1] - https://invent.kde.org/plasma/xdg-desktop-portal-kde/-/blob/master/src/request.cpp
[2] - https://invent.kde.org/libraries/xdg-portal-test-kde/-/blob/master/src/portaltest.cpp#L342
Comment 2 Carlo 2021-05-03 10:10:35 UTC
I tried your portal-test as host application and it works for me as well.
At this point I don't know what to change in my demo.. I am fairly new to dbus and I cannot explain to myself why it works on GNOME, but it does not on KDE.

Would you please be so kind to try helping me debugging it? I am using python dbus API + Gtk because I'd like to then write a merge request for a Gtk app written in python

P.S. I also tried to make an asynchronous call to Close(), but it didn't help. It just changed the error it displayed to
GDBus.Error:org.freedesktop.DBus.Error.UnknownObject: No such object path '/org/freedesktop/portal/desktop/request/1_204/t'

where 1_204/t is the handle returned by Inhibit
Comment 3 Carlo 2021-05-03 10:13:28 UTC
actually: i think the UnknownObject error is due to the fact that i tried to click the toggle multiple times trying to close the request.
The first time still gets org.freedesktop.DBus.Error.NoReply, so there is really no change with asynch calls
Comment 4 Jan Grulich 2021-05-03 10:22:20 UTC
I tried your app, but it doesn't even inhibit the session. Clicking on the button doesn't do anything for me.
Comment 5 Carlo 2021-05-03 10:30:29 UTC
On KDE? That's strange, powerdevil seems to detect it on my system: https://i.imgur.com/eEJUAVh.png

I assume the systems has installed: Gtk4, dbus-python and python-gobject
Comment 6 Jan Grulich 2021-05-03 10:34:28 UTC
I'm on Wayland, that will be the reason why it doesn't work.
Comment 7 Jan Grulich 2021-05-03 10:35:59 UTC
with GDK_BACKEND=X11 I get:
Traceback (most recent call last):
  File "/home/jgrulich/foo.py", line 59, in <lambda>
    self.connect('activate', lambda app: app.on_activate())
  File "/home/jgrulich/foo.py", line 75, in on_activate
    self.win = Gtk.Window(application=self, title="A window")
  File "/usr/lib/python3.9/site-packages/gi/overrides/Gtk.py", line 519, in __init__
    raise RuntimeError(
RuntimeError: Gtk couldn't be initialized. Use Gtk.init_check() if you want to handle this case.
Comment 8 Carlo 2021-05-03 10:51:45 UTC
Could the X11 error due to the fact that the DISPLAY variable is not set?

On Wayland you may want to try this version of the demo, where I don't try to get toplevel's handle to pass to the Portal: https://pastebin.com/raw/tziTenUa
Comment 9 Jan Grulich 2021-05-03 10:57:02 UTC
It does release inhibition when I close the app.

method call time=1620039298.850438 sender=:1.42 -> destination=:1.56 serial=1330 path=/org/freedesktop/portal/desktop/request/1_384/t; interface=org.freedesktop.impl.portal.Request; member=Close
method call time=1620039298.850706 sender=:1.56 -> destination=org.kde.Solid.PowerManagement serial=1506 path=/org/kde/Solid/PowerManagement/PolicyAgent; interface=org.kde.Solid.PowerManagement.PolicyAgent; member=ReleaseInhibition
   uint32 323
Comment 10 Carlo 2021-05-03 11:02:05 UTC
Yes, I noticed that!
But I think it's the Portal that un-inhibits the session when it detects the peer has exited. But I don't make the Close() call on exit
Comment 11 Carlo 2021-05-03 11:44:48 UTC
Oh I just realised that in my demo it is not clear that if you click a second time on "Toggle Inhibtion", it uninhibits the session.
That is what caused me problems.
Comment 13 Carlo 2021-09-29 23:02:40 UTC
Confirming the fix works for me as well!
Many thanks ^^