Bug 507239 - Old inotify instances not cleaned up when changing desktop location in Folder View settings
Summary: Old inotify instances not cleaned up when changing desktop location in Folder...
Status: RESOLVED FIXED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Desktop icons & Folder View widget (other bugs)
Version First Reported In: 6.3.5
Platform: Debian testing Linux
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-19 19:29 UTC by Kunal
Modified: 2025-07-25 15:14 UTC (History)
3 users (show)

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


Attachments
Location tab (40.86 KB, image/png)
2025-07-19 19:29 UTC, Kunal
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kunal 2025-07-19 19:29:44 UTC
Created attachment 183348 [details]
Location tab

SUMMARY

When changing the location of the desktop in the Folder View widget (right click on the desktop ->  Desktop and Wallpaper -> Location tab), changing back to the previous location after applying does not clean up the inotify instance associated with the old directory.

STEPS TO REPRODUCE


1. Navigate to the Location tab in the Desktop Folder Settings

2. Open a terminal and use the command "kde-inotify-survey" and look for the number of watches and instances under plasmashell:

kunal@Kunal-deb:~$ kde-inotify-survey | grep -A 4 "plasmashell"
            "cmdline": "/usr/bin/plasmashell\u0000",
            "instances": 6,
            "pid": 2853529,
            "uid": 1000,
            "watches": 20


3. Change the folder to anything else (for example changing from the "Desktop folder" option (first option)  to "Places panel item: Home" (3rd option)

4. Hit Apply

5. Change the folder back to what it was before and hit Apply again.

6. Rerun the command and note the number of watches:

kunal@Kunal-deb:~$ kde-inotify-survey | grep -A 4 "plasmashell"
            "cmdline": "/usr/bin/plasmashell\u0000",
            "instances": 8,
            "pid": 2853529,
            "uid": 1000,
            "watches": 21


Continue changing the option, applying, and changing back, applying again, and notice how the number watches will permanently increment without being cleaned up:

kunal@Kunal-deb:~$ kde-inotify-survey | grep -A 4 "plasmashell"
            "cmdline": "/usr/bin/plasmashell\u0000",
            "instances": 32,
            "pid": 2851731,
            "uid": 1000,
            "watches": 33



OBSERVED RESULT

Each time the desktop location is changed and changed back, the number of watches increases by 1 and the number of instances increases by 2 for plasmashell when observing the output of kde-inotify-survey.  

EXPECTED RESULT

Inotify instances that are no longer in use should be cleaned up instead of duplicates being created. The number of "watches" and "instances" under plasmashell in kde-inotify-survey should revert back to baseline prior to changing the folder and back. 

SOFTWARE/OS VERSIONS

Operating System: Debian GNU/Linux 13
KDE Plasma Version: 6.3.5
KDE Frameworks Version: 6.13.0
Qt Version: 6.8.2
Kernel Version: 6.12.35+deb13-amd64 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 9800X3D 8-Core Processor
Memory: 60.5 GiB of RAM
Graphics Processor 1: NVIDIA GeForce RTX 5080
Graphics Processor 2: AMD Radeon Graphics

ADDITIONAL INFORMATION
This also occurs when programmatically changing the the desktop config using DBus and executing a script (qdbus6 org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript), which can exhaust the inotify instance pool over time. The current workaround seems to be killing and restarting plasmashell entirely. 


tracing the inotify_add_watch syscall and changing the folders back and forth confirms plasmashell is not removing the old inotify instances while adding new ones:

kunal@Kunal-deb:~$ sudo bpftrace -e 'tracepoint:syscalls:sys_enter_inotify_add_watch /comm == "plasmashell"/ { printf("Path: %s\n", str(args->pathname)); }'
Attaching 1 probe...
Path: file:///home/kunal
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Path: /home/kunal/Desktop/
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Path: file:///home/kunal
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Path: /home/kunal/Desktop/
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Path: file:///home/kunal
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Path: /home/kunal/Desktop/
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Path: file:///home/kunal
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Path: /home/kunal/Desktop/
Path: /home/kunal/.config/plasma-org.kde.plasma.desktop-appletsrc
Comment 1 Bug Janitor Service 2025-07-21 05:06:01 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-desktop/-/merge_requests/3113
Comment 2 Harald Sitter 2025-07-22 15:31:23 UTC
Git commit 3778406f985a169ffec95768e476f8daf9281a53 by Harald Sitter.
Committed on 22/07/2025 at 12:43.
Pushed by sitter into branch 'master'.

foldermodel: delete previous qfilesystemwatcher

lest we leak the previous pointer

M  +3    -0    containments/desktop/plugins/folder/foldermodel.cpp

https://invent.kde.org/plasma/plasma-desktop/-/commit/3778406f985a169ffec95768e476f8daf9281a53
Comment 3 Harald Sitter 2025-07-23 00:17:32 UTC
Git commit 7003b49f386f5e1d89d93e00dee1ae4759479a98 by Harald Sitter.
Committed on 23/07/2025 at 00:17.
Pushed by sitter into branch 'Plasma/6.4'.

foldermodel: delete previous qfilesystemwatcher

lest we leak the previous pointer
(cherry picked from commit 3778406f985a169ffec95768e476f8daf9281a53)

M  +3    -0    containments/desktop/plugins/folder/foldermodel.cpp

https://invent.kde.org/plasma/plasma-desktop/-/commit/7003b49f386f5e1d89d93e00dee1ae4759479a98