Public bug reported:

[ Impact ]

GLib 2.88.0 (Ubuntu 26.04, libglib2.0-0t64 2.88.0-1ubuntu0.1) has upstream bug
https://gitlab.gnome.org/GNOME/glib/-/issues/4055: when two GFileMonitors watch 
the same inode through
different paths, they share one kernel inotify watch descriptor. Cancelling one 
of them calls
inotify_rm_watch() on the shared wd, so the other monitor silently stops 
receiving events
(g_file_monitor_is_cancelled() stays FALSE).

Real-world effect on a default Ubuntu desktop with Timeshift (rsync
mode) on an external disk:

1. The external disk is mounted by the desktop at /run/media/$USER/<disk>; 
gvfsd-trash monitors its .Trash-1000.
2. Timeshift's cron job /etc/cron.d/timeshift-hourly runs `timeshift --check 
--scripted` every hour. It mounts
   the same filesystem a second time at /run/timeshift/<pid>/backup and 
unmounts it < 1 s later.
3. gvfsd-trash also starts monitoring the second mount's .Trash-1000 (same 
inodes → same wd). When that mount
   goes away, its monitor is cancelled and the shared kernel watch is removed.
4. From then on files deleted on the external disk never show up in Files → 
Trash or in the Dock trash
   icon, until gvfsd-trash is restarted or the user logs out and in again.

The fix is already upstream: commit 3457cf66426dc48eee1f61b1b2818d2f4feec01b 
(MR !5369, merged 2026-09-22),
contained in GLib 2.90.1 (glib-2-90 and main). It is not on the glib-2-88 
branch.

[ Test Plan ]

Self-contained reproducer (no root needed; symlink alias = same inode,
same as a second mount):

```
mkdir -p /tmp/wdtest/real && ln -sfn real /tmp/wdtest/alias
python3 - <<'EOF'
import os
from gi.repository import Gio, GLib
ctx = GLib.MainContext.default()
def pump(n=20):
    for _ in range(n):
        while ctx.iteration(False): pass
        GLib.usleep(50000)
def watches():
    n = 0
    for fd in os.listdir("/proc/self/fd"):
        try:
            if os.readlink(f"/proc/self/fd/{fd}") == "anon_inode:inotify":
                n += sum(1 for l in open(f"/proc/self/fdinfo/{fd}") if 
l.startswith("inotify"))
        except OSError: pass
    return n
ev = []
m1 = 
Gio.File.new_for_path("/tmp/wdtest/real").monitor_directory(Gio.FileMonitorFlags.NONE,
 None)
m1.connect("changed", lambda m, f, o, e: ev.append(f.get_basename()))
m2 = 
Gio.File.new_for_path("/tmp/wdtest/alias").monitor_directory(Gio.FileMonitorFlags.NONE,
 None)
pump(); print("kernel watches:", watches())
m2.cancel(); pump(); print("after cancelling alias monitor, kernel watches:", 
watches())
open("/tmp/wdtest/real/b.txt", "w").close(); pump(); print("remaining monitor 
got event:", "b.txt" in ev)
EOF
```

Result on 2.88.0-1ubuntu0.1:
```
kernel watches: 1
after cancelling alias monitor, kernel watches: 0
remaining monitor got event: False
```
Expected with the fix: watches stays 1 and the event is received (True).

Desktop test: Timeshift (rsync) on an external disk, delete a file on that disk 
after the next full hour →
it must appear in Files → Trash and the Dock icon must show a full trash.

Evidence from the affected machine: gvfsd-trash's inotify watches on the 
external disk (read from
/proc/<pid>/fdinfo, sampled every 0.3 s) went from 3 to 0 at the exact moment 
the Timeshift mount was removed:
```
10:00:01.454 storage_watches=3 timeshift_mounts=1
10:00:01.881 storage_watches=0 timeshift_mounts=0
```

[ Where problems could occur ]

The patch only changes when GLib's inotify backend calls inotify_rm_watch() (it 
now checks whether another
watched directory/file still uses the same wd). A mistake there could leak a 
kernel watch (watch kept after
the last monitor is gone) or keep delivering events to a stale path. It ships 
with an upstream regression test.

[ Other Info ]

- Ubuntu 26.04 (resolute), libglib2.0-0t64 2.88.0-1ubuntu0.1, gvfs 
1.60.0-1ubuntu0.2, kernel 7.0.
- Any second mount of the same filesystem (Timeshift, a bind mount, a backup 
tool) triggers it, not only Timeshift.
- Upstream issue: https://gitlab.gnome.org/GNOME/glib/-/issues/4055
- Upstream commit: 
https://gitlab.gnome.org/GNOME/glib/-/commit/3457cf66426dc48eee1f61b1b2818d2f4feec01b

** Affects: glib2.0 (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2175481

Title:
  [SRU] Backport GLib fix "inotify: don't remove shared kernel watch
  while still in use" (upstream #4055) to 26.04 — Trash stops showing
  items on external disks after Timeshift's hourly check

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/glib2.0/+bug/2175481/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to