-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[Linux] psutil does not handle ENAMETOOLONG when accessing process file descriptors in procfs #1940
Comments
I'm going to prepare PR with a fix |
Interesting. I agree we should ignore ENAMETOOLONG and continue both in |
nradchenko
changed the title
[Linux] psutil does not handle ENAMETOOLONG when accessing process file descriptors
[Linux] psutil does not handle ENAMETOOLONG when accessing process file descriptors in procfs
Apr 29, 2021
nradchenko
added a commit
to nradchenko/psutil
that referenced
this issue
Jun 2, 2021
…ampaolo#1940) When resolving process file descriptors symlinks in procfs (/proc/PID/fd/FD), the kernel can only deal with file paths no longer than PAGE_SIZE (which usually equals to PATH_MAX). https://elixir.bootlin.com/linux/v5.12/source/fs/proc/base.c#L1759 Resolving fd symlink that corresponds to a file with a path longer than PATH_MAX with readlink(2) would result in ENAMETOOLONG error (see details in giampaolo#1940). We can do nothing to fix this in userspace; therefore these errors should be ignored.
nradchenko
added a commit
to nradchenko/psutil
that referenced
this issue
Jun 2, 2021
When resolving process file descriptors symlinks in procfs (/proc/PID/fd/FD), the kernel can only deal with file paths no longer than PAGE_SIZE (which usually equals to PATH_MAX). https://elixir.bootlin.com/linux/v5.12/source/fs/proc/base.c#L1759 Resolving fd symlink that corresponds to a file with a path longer than PATH_MAX with readlink(2) would result in ENAMETOOLONG error (see details in giampaolo#1940). We can do nothing to fix this in userspace; therefore these errors should be ignored.
nradchenko
added a commit
to nradchenko/psutil
that referenced
this issue
Jun 2, 2021
When resolving process file descriptors symlinks in procfs (/proc/PID/fd/FD), the kernel can only deal with file paths no longer than PAGE_SIZE (which usually equals to PATH_MAX). https://elixir.bootlin.com/linux/v5.12/source/fs/proc/base.c#L1759 Resolving fd symlink that corresponds to a file with a path longer than PATH_MAX with readlink(2) would result in ENAMETOOLONG error (see details in giampaolo#1940). We can do nothing to fix this in userspace; therefore these errors should be ignored.
giampaolo
pushed a commit
that referenced
this issue
Oct 5, 2021
When resolving process file descriptors symlinks in procfs (/proc/PID/fd/FD), the kernel can only deal with file paths no longer than PAGE_SIZE (which usually equals to PATH_MAX). https://elixir.bootlin.com/linux/v5.12/source/fs/proc/base.c#L1759 Resolving fd symlink that corresponds to a file with a path longer than PATH_MAX with readlink(2) would result in ENAMETOOLONG error (see details in #1940). We can do nothing to fix this in userspace; therefore these errors should be ignored.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
Description
Recently I've discovered that
net_connections()
fails sometimes on our storage servers. These hosts have a lot of files which are processed by rsync almost 24/7. The error was like this:OS error: [Errno 36] File name too long: '/proc/5259/fd/12
.After some digging it turned out that we have a number of files stored at deep filesystem directory levels, which are occasionally opened by rsync for reading or writing. Paths of such files may exceed
PATH_MAX
, which results in broken magic symlinks in procfs.The bug can be reproduced with the following steps:
PATH_MAX
(4096 usually):Press Ctrl+Z or open a new terminal window at this point.
net_connections()
and see what happens:Let's inspect the directory and see what the problem with this symlink is:
My tests show that there seems to be no way to find out where this magic symlink points at all, even when calling
readlink
with large buffer:How to fix
I suggest to ignore this kind of errors.
Skipping it in
net_connections()
is fine because these broken fds are not needed for preparing network connections list - netstat and ss do not report any errors like that.And skipping it in
psutil.Process.open_files()
should be fine too, as there's nothing else we can actually do to fix this in userspace.The text was updated successfully, but these errors were encountered: