Skip to content
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

[BUG] lsof hangs on Ubuntu 24.10 if executed from within another process #328

Open
JaagupAverin opened this issue Jan 6, 2025 · 4 comments

Comments

@JaagupAverin
Copy link

Describe the bug

  • Running lsof directly from terminal always works fine.
  • Running lsof from another process, such as from Rust, Python or even a bash script, causes the process to hang.
    • Running lsof with -O or -b flag still works fine
    • Running lsof with sudo still works fine.

Another detail is that when running with -O or -b flags, there is a single process that runs for ~10 seconds, but if run without them the process hangs for several minutes and there is also a child process that's always near 100% CPU: image

To Reproduce

#!/bin/bash

echo "Running lsof -O"
lsof -O
echo "--- Worked ---"

echo "Running lsof -bw"
lsof -bw
echo "--- Worked ---"

echo "Running sudo lsof"
sudo lsof
echo "--- Worked ---"

echo "Running lsof"
lsof
echo "-- Won't get here ---"

Expected behavior
Final call from given script to finish in several seconds and not to hang for upto 4-6 minutes.

Environment (please complete the following information):

  • Kernel: 6.11.0-13-generic
  • OS: Ubuntu 24.10
lsof version information:
    revision: 4.95.0
    latest revision: https://github.com/lsof-org/lsof
    latest FAQ: https://github.com/lsof-org/lsof/blob/master/00FAQ
    latest (non-formatted) man page: https://github.com/lsof-org/lsof/blob/master/Lsof.8
    compiler: cc
    compiler version: 13.2.0 (Ubuntu 13.2.0-23ubuntu4)
    compiler flags: -g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/lsof-ae6xi3/lsof-4.95.0=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/lsof-ae6xi3/lsof-4.95.0=/usr/src/lsof-4.95.0-1.1 -Wdate-time -D_FORTIFY_SOURCE=3 -DLINUXV=68001 -DGLIBCV=239 -DHASIPv6 -DNEEDS_NETINET_TCPH -DHASSELINUX -DHASUXSOCKEPT -DHASPTYEPT -DHASSOSTATE -DHASSOOPT -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DHAS_STRFTIME -DLSOF_VSTR="6.8.1" -I/usr/include/tirpc -O
    loader flags: -L./lib -llsof -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now -ltirpc -lselinux
    Anyone can list all files.
    /dev warnings are disabled.
    Kernel ID check is disabled.

Additional context
Add any other context about the problem here.

@jiegec
Copy link
Contributor

jiegec commented Jan 7, 2025

Ubuntu seemed to be using a old version of lsof. Could you please try and use the latest version?

@jiegec
Copy link
Contributor

jiegec commented Jan 7, 2025

Reproduction of lsof 4.95.0 on Ubuntu 24.04:

Running lsof -O

real    0m0.218s
user    0m0.078s
sys     0m0.124s
--- Worked ---
Running lsof -bw

real    0m0.159s
user    0m0.050s
sys     0m0.098s
--- Worked ---
Running sudo lsof

real    0m28.599s
user    0m0.003s
sys     0m0.008s
--- Worked ---
Running lsof

real    0m0.227s
user    0m0.089s
sys     0m0.124s
-- Won't get here ---

It does not hang there. Could you please provide a strace with timestamps?

@JaagupAverin
Copy link
Author

JaagupAverin commented Jan 7, 2025

So after a reboot my test script worked with right away, producing this log: strace-lsof-4.95-works.txt
However when lsof is called from Zed, the lsof process still hanged. I added strace to the call in Zed and it produced this log: strace-zed-lsof-4.95-hangs.txt
Afterwards, I tried running my test script again, which no longer worked and also started hanging again producing this log: strace-lsof-4.95-hangs.txt
(added -p424242 to reduce spam).

So the issue does boil down to some specific curiosity in how the process is called from Zed. However everything works great with 4.99 so perhaps getting Ubuntu's package updated is the real issue here.

@jiegec
Copy link
Contributor

jiegec commented Jan 7, 2025

I have a guess about #316 and #190 being the real fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants