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

Files exported by --file-forwarding not removed from xdg-document-portal after program exit #4303

Closed
teohhanhui opened this issue Jun 3, 2021 · 9 comments

Comments

@teohhanhui
Copy link

teohhanhui commented Jun 3, 2021

Linux distribution and version

openSUSE MicroOS (20210524)

Flatpak version

Flatpak 1.11.1

Description of the problem

The documentation for --file-forwarding notes that:

The exports are non-persistent

flatpak/doc/flatpak-run.xml

Lines 627 to 638 in 686af7d

<varlistentry>
<term><option>--file-forwarding</option></term>
<listitem><para>
If this option is specified, the remaining arguments are scanned, and all arguments
that are enclosed between a pair of '@@' arguments are interpreted as file paths,
exported in the document store, and passed to the command in the form of the
resulting document path. Arguments between '@@u' and '@@' are considered uris,
and any file: uris are exported. The exports are non-persistent and with read and write
permissions for the application.
</para></listitem>
</varlistentry>

However, often times files exported this way are not removed even after the program started by flatpak run has exited. This is causing target is busy when trying to unmount a partition on a USB external hard drive.

Steps to reproduce

  1. flatpak install io.github.celluloid_player.Celluloid
  2. gio open ???.mkv
  3. Exit the Celluloid player started above.
  4. Note the file descriptor for the ???.mkv video file is still open by xdg-document-portal, e.g. by running lsof /dev/sda1
@smcv
Copy link
Collaborator

smcv commented Jun 10, 2021

This might be a file descriptor leak in the xdg-document-portal, which is not actually part of Flatpak. Which version of xdg-desktop-portal do you have?

xdg-desktop-portal version 1.8.1 definitely fixed a fd leak, for example.

@teohhanhui
Copy link
Author

xdg-desktop-portal is at version 1.8.1, but I'm definitely still seeing these fd's being left open.

teohhanhui@envy-x360:~> sudo pkcon get-packages --filter=installed | grep xdg-desktop-portal
Installed    xdg-desktop-portal-1.8.1-1.2.x86_64 (installed)
Installed    xdg-desktop-portal-gtk-1.8.0-1.6.x86_64 (installed)

Do you mean flatpak is correctly requesting the removal of such forwarded files on app exit?

@teohhanhui
Copy link
Author

teohhanhui commented Jun 14, 2021

I can only find the xdp_dbus_documents_call_add_sync call here:

if (!xdp_dbus_documents_call_add_sync (documents,

But there's no xdp_dbus_documents_call_delete_sync call on app exit. It seems to only be done in document-unexport command:

if (!xdp_dbus_documents_call_delete_sync (documents, doc_id, NULL, error))

EDIT: Oh, okay, there's the 4th argument passed to xdp_dbus_documents_call_add_sync which is supposed to make it non-persistent?

IN b persistent:
     whether to add the file only for this session or permanently

https://flatpak.github.io/xdg-desktop-portal/portal-docs.html#gdbus-method-org-freedesktop-portal-Documents.AddNamed

What does session mean here? The desktop session? If that's the case, that's still going to prevent unmounting external hard drives... 😞

@rowbawts
Copy link

rowbawts commented Feb 8, 2022

I'm having the same issue with Clapper when I plug in an SD card and play some videos, close down Clapper and try and eject the SD card gnome tells me volume is busy and running lsof on the mounted device it shows xdg-document-portal keeps them open.

Edit:
Fedora 35 Silverblue - Flatpak 1.12.4

@DaAwesomeP
Copy link

DaAwesomeP commented Mar 1, 2023

I'm seeing this on openSUSE Leap 15.3 with Flatpak 1.12.5. In my case it is when downloading files in Firefox running in Flatpak.

Are there any known workarounds? Possibly:

  • Will temporarily (and manually) adding the location to the Flatpak permissions for the application cause the application to access the file directly instead of using xdg-document-portal?
  • Is there a way to force-close or kill xdg-document-portal to cause it to close all of the file descriptors? Or is there a way to simply force those descriptors to close? Does this create a large risk of data loss?

EDIT: If you are willing to risk it or are very sure that no more data is being written (seems reasonably safe for a finished Firefox download), then you can simply kill the xdg-document-portal process. This is in no way a blanket solution for all scenarios.

@hfiguiere
Copy link
Collaborator

Likely flatpak/xdg-desktop-portal#689

@hfiguiere
Copy link
Collaborator

This should be fixed when the portal with the fix for #689 get released.

@hfiguiere
Copy link
Collaborator

This should be fixed if you use xdg-desktop-portal 1.18.2.

@GeorgesStavracas
Copy link
Member

Correct, xdg-desktop-portal 1.18.2 should fix this.

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

No branches or pull requests

6 participants