Bug 469889

Summary: plasmashell leaks inotify file descriptor
Product: [Plasma] plasmashell Reporter: Andreas Schwab <schwab>
Component: generalAssignee: Plasma Bugs List <plasma-bugs>
Status: RESOLVED UPSTREAM    
Severity: normal CC: johannes+kdebugs, josh, kde, nate, sitter
Priority: NOR    
Version First Reported In: 5.27.4   
Target Milestone: 1.0   
Platform: openSUSE   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Andreas Schwab 2023-05-17 12:02:38 UTC
Start konsole from the start menu.  In the shell run:

$ lsof -p $$ | grep inotify
bash    4183 test   21r  a_inode   0,14        0   10036 inotify
$ lsof -p $(pidof konsole) | grep inotify
konsole 4171 test    9r  a_inode               0,14         0   10036 inotify
konsole 4171 test   21r  a_inode               0,14         0   10036 inotify
$ lsof -p $(pidof plasmashell) | grep inotify
plasmashe 3594 test    9r  a_inode               0,14         0   10036 inotify
plasmashe 3594 test   18r  a_inode               0,14         0   10036 inotify
plasmashe 3594 test   21r  a_inode               0,14         0   10036 inotify
Comment 1 Andreas Schwab 2023-05-17 12:13:15 UTC
This also happens when konsole is started from krunner.
Comment 2 Johannes Truschnigg 2023-11-01 13:23:38 UTC
I can confirm this bug on both Debian 12 and Arch Linux, where it looks like the following:


$ ls -l /proc/$$/fd/
total 0
lrwx------ 1 colo colo 64  1. Nov 13:37 0 -> /dev/pts/3
lrwx------ 1 colo colo 64  1. Nov 13:37 1 -> /dev/pts/3
lrwx------ 1 colo colo 64  1. Nov 13:37 2 -> /dev/pts/3
lr-x------ 1 colo colo 64  1. Nov 13:37 24 -> anon_inode:inotify
lrwx------ 1 colo colo 64  1. Nov 13:37 255 -> /dev/pts/3
$ pstree -s -p $$
systemd(1)───systemd(616)───plasmashell(754)───konsole(60566)───bash(60581)───pstree(61213)
$ ls -l /proc/60566/fd/24
lr-x------ 1 colo colo 64  1. Nov 14:02 /proc/60566/fd/24 -> anon_inode:inotify
$ ls -l /proc/754/fd/24
lr-x------ 1 colo colo 64  1. Nov 14:02 /proc/754/fd/24 -> anon_inode:inotify
$ sudo ls -l /proc/616/fd/24
lrwx------ 1 colo colo 64  1. Nov 14:03 /proc/616/fd/24 -> 'socket:[18811]'


I stumbled over this because the fd broke another project's test suite I was running in my Konsole-spawned shell.
Comment 3 David Edmundson 2023-11-01 13:36:05 UTC Comment hidden (spam)
Comment 4 David Edmundson 2023-11-01 13:59:37 UTC
I think it's here:

https://github.com/libimobiledevice/libusbmuxd/blob/master/src/libusbmuxd.c

I can't see a 

            fcntl(inot_fd, F_SETFD, FD_CLOEXEC);


Will try to build locally to confirm
Comment 5 Harald Sitter 2023-11-01 14:00:55 UTC
regardless it should really use inotify_init1 which allows setting FD_CLOEXEC without race FWIW
Comment 6 David Edmundson 2023-11-01 14:34:18 UTC
https://github.com/libimobiledevice/libusbmuxd/pull/133

If you are able to confirm this fixes the leak that would be appreciated
Comment 7 Andreas Schwab 2023-11-08 16:39:19 UTC
With that patch the leak is gone.
Comment 8 David Edmundson 2023-11-08 16:41:05 UTC
Thanks for confirming