After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 763218 - Trash enumeration is not synchronized with the system
Trash enumeration is not synchronized with the system
Status: RESOLVED FIXED
Product: nautilus
Classification: Core
Component: Trash
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Allison Karlitskaya (desrt)
gvfs-maint
: 749372 763394 (view as bug list)
Depends on: 711459
Blocks:
 
 
Reported: 2016-03-07 11:39 UTC by Razvan Chitu
Modified: 2016-04-26 12:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
trash: Check modification time to be sure rescan is not needed (3.82 KB, patch)
2016-03-09 14:56 UTC, Ondrej Holy
rejected Details | Review
trash-monitor: change trash monitoring process (3.79 KB, patch)
2016-03-14 09:49 UTC, Razvan Chitu
none Details | Review
trash-monitor: change trash monitoring process (4.14 KB, patch)
2016-03-14 22:49 UTC, Razvan Chitu
committed Details | Review

Description Razvan Chitu 2016-03-07 11:39:33 UTC
If the trash contents are enumerated right after a trash operation, the trashed file appears not to be there. I suspect this is due to the trash backend using an internal cache for enumeration, which does not get updated immediately.

This issue affects nautilus because restoring files from the trash is done by querying the contents of the trash. Since they are not updated quick enough, the trashed files will appear not to be there.
Comment 1 Ondrej Holy 2016-03-09 14:54:56 UTC
The "cache" for filesystems with reliable notifications is updated on signals from g_file_monitor only if trash dir is being monitored. I suppose that the file notifications might be delayed and thus the file might not be listed immediately after g_file_trash. However, I am not able to reproduce such situation (even not when trashing thousands of files), so I can't test it :-( Are you able to reproduce it using some "simple" code?
Comment 2 Ondrej Holy 2016-03-09 14:56:49 UTC
Created attachment 323516 [details] [review]
trash: Check modification time to be sure rescan is not needed

Rescan trash directory also on filesystems with reliable notifications,
because notifications might be delayed and thus trash_dir_rescan is
still needed in order to be sure that trashed file is listed from the
backend immediately after g_file_trash call.
Comment 3 Ondrej Holy 2016-03-09 14:57:16 UTC
Razvan, could you try the attached patch whether it fixes mentioned problems for you?
Comment 4 Ondrej Holy 2016-03-09 15:03:16 UTC
Comment on attachment 323516 [details] [review]
trash: Check modification time to be sure rescan is not needed

Sorry, I've messed up the description of the patch (I used description for another patch, which just forces rereading, but I do not intend to publish it)... 

Check modification time on trash directory even if it is on a filesystem with reliable notifications, because notifications might be delayed and thus trash_dir_rescan is still needed in order to be sure that trashed file is listed from the backend immediately after g_file_trash call.
Comment 5 Allison Karlitskaya (desrt) 2016-03-09 15:40:07 UTC
Are you certain that this isn't really bug 749314?
Comment 6 Ondrej Holy 2016-03-11 08:38:34 UTC
Ryan, thank for notice, I didn't know about it, but it is probably something else...
Comment 7 Ondrej Holy 2016-03-11 08:46:27 UTC
Comment on attachment 323516 [details] [review]
trash: Check modification time to be sure rescan is not needed

I realized that the patch is a bit wrong and it forces rereading after each change, because mtime isn't actualized by the signals (I thought that trash_dir_enumerate is invoked when signal comes, but it isn't... ). So the patch ensures that enumerate contains all the files, but it is not right way to do this...
Comment 8 Ondrej Holy 2016-03-11 08:53:14 UTC
However, it seems that file monitor signals are fast enough according to my testing. It seems that there is another problem. The bug appears only in Nautilus when undoing trash operation for thousands of files (and the attached patch doesn't have any influence on it)...

Debug output shows that Nautilus floods trash backend by thousands of enumeration jobs. Trash backend is not able to handle all those requests... and you can see high cpu usage for several minutes... as a consequence the jobs probably timeout and you can see following warnings:
** (process:30930): WARNING **: send_infos_cb: No such interface 'org.gtk.vfs.Enumerator' on object at path /org/gtk/vfs/client/enumerator/732 (g-dbus-error-quark, 19)

Nautilus seems to wait for a result from the latest enumeration job, but it won't get the result probably because the operation timeouts before... so it won't complete the undo operation even after the several minutes.

We have to figure out why thousands of enumeration requests are queued and deal with it somehow...
Comment 9 Ondrej Holy 2016-03-11 09:09:29 UTC
*** Bug 763394 has been marked as a duplicate of this bug. ***
Comment 10 Ondrej Holy 2016-03-11 09:10:12 UTC
(In reply to Allison Ryan Lortie (desrt) from comment #5)
> Are you certain that this isn't really bug 749314?

Actually, the file monitor changes mentioned in this bug might be a root of the problem... Because nautilus/xfdesktop got notifications earlier and thus spawns enumerations earlier...
Comment 11 Razvan Chitu 2016-03-14 09:49:50 UTC
Created attachment 323843 [details] [review]
trash-monitor: change trash monitoring process

In Nautilus, the trash is monitored for state changes - going from empty to
non-empty and the other way round. Monitoring is done by handling change signals
from a regular file monitor. On each signal, an enumeration of the trash
contents is started in order to see if it is empty or not. This causes issues
when many files are trashed, because the gvfs trash backend is flooded with
enumeration requests, resulting in CPU usage spikes. In order to fix this, the
"item-count" attribute of the trash should be queried instead.

Replace asynchronous enumeration with asynchronous information query and update
the trash state based on the "item-count" attribute.
Comment 12 Razvan Chitu 2016-03-14 22:49:04 UTC
Created attachment 323932 [details] [review]
trash-monitor: change trash monitoring process

In Nautilus, the trash is monitored for state changes - going from empty to
non-empty and the other way round. Monitoring is done by handling change signals
from a regular file monitor. On each signal, an enumeration of the trash
contents is started in order to see if it is empty or not. This causes issues
when many files are trashed, because the gvfs trash backend is flooded with
enumeration requests, resulting in CPU usage spikes. In order to fix this, the
"item-count" attribute of the trash should be queried instead.

Replace asynchronous enumeration with asynchronous information query and update
the trash state based on the "item-count" attribute.
Comment 13 Ondrej Holy 2016-03-15 12:07:35 UTC
I realized that some modifications are needed for the trash backend in order to be sure that valid item-count is reported. See Bug 711459.
Comment 14 Carlos Soriano 2016-04-07 20:10:24 UTC
Review of attachment 323932 [details] [review]:

LGTM thanks!!
Comment 15 Razvan Chitu 2016-04-07 21:14:30 UTC
Attachment 323932 [details] pushed as a99b4cf - trash-monitor: change trash monitoring process
Comment 16 Ondrej Holy 2016-04-08 06:33:55 UTC
*** Bug 749372 has been marked as a duplicate of this bug. ***
Comment 17 Christian Stadelmann 2016-04-26 11:25:40 UTC
Will this fix be included in 3.20.x too?
Comment 18 Ondrej Holy 2016-04-26 11:31:21 UTC
GVfs part is aleady in gnome-3-20, not sure about Nautilus and GTK+ part...
Comment 19 Christian Stadelmann 2016-04-26 12:11:33 UTC
According to git, they nautilus and gtk+ part are not.