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

Fix file descriptor leak #989

Merged
merged 1 commit into from
Feb 20, 2017
Merged

Fix file descriptor leak #989

merged 1 commit into from
Feb 20, 2017

Conversation

pchaigno
Copy link
Contributor

If you keep tools/ustat.py running for more than 17min (with 1sec refresh) it errors out with too many open files. Other tools may be affected.

Copy link
Collaborator

@goldshtn goldshtn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for catching this.

@4ast
Copy link
Member

4ast commented Feb 20, 2017

Great catch!

@4ast 4ast merged commit 203fd27 into iovisor:master Feb 20, 2017
@pchaigno pchaigno deleted the fix-fd-leak branch February 20, 2017 07:28
@vitalyvch
Copy link

Exellent !-)

@drandynisbet
Copy link

H'mm I'm getting a too many open files issue with
ustat -l java ...
create_probe_event: open(/sys/kernel/debug/tracing/uprobe_events): Too many open files
Traceback (most recent call last):
File "/usr/share/bcc/tools/lib/ustat", line 305, in
File "/usr/share/bcc/tools/lib/ustat", line 297, in run
File "/usr/share/bcc/tools/lib/ustat", line 246, in _loop_iter
File "/usr/share/bcc/tools/lib/ustat", line 237, in _attach_probes
File "/usr/lib/python2.7/dist-packages/bcc/init.py", line 1023, in attach_uprobe
Exception: Failed to attach BPF to uprobe

@yonghong-song
Copy link
Collaborator

A file descriptor leaking issues. Could you debug this a little more? You can hack bcc to stop/wait right after the above error appears, and then check file descriptors usr /proc//fd and /proc//fdinfo. That will give a clue what hold on file descriptors.

@drandynisbet
Copy link

drandynisbet commented Sep 24, 2019

Hi it seems to increase by circa 7 file descriptors each time the timeout is reached for ustat - Please see attached file descriptor list and info ... obviously I did not wait for it to exhaust my file descriptor list - but you can see the picture ...
FDINFO.txt
FDLIST.txt

@yonghong-song
Copy link
Collaborator

there are a lot of bpf prog/map file descriptors. Maybe they should be closed but did not? I tried simple sudo ./ustat.py -l java and cannot reproduce the issue. Could you post your complete command line which triggers the issue?

@drandynisbet
Copy link

drandynisbet commented Sep 24, 2019

My ulimit is set by default for open files to (-n) 1024
Not that it matters which one but you probably need a java program running ....
/usr/bin/java -jar xMandelbrot.jar
I'm using openjdk 8 but that shouldn't matter either.
I also set the dropdown MAXITERATIONS to 50000 on the GUI ... again that shouldn't matter ...
Downloaded the jar (I think) from http:https://math.hws.edu/xJava/MB/xMandelbrot.jar
sudo ./ustat.py -l java
Takes circa 5minutes to exhaust file descriptors on my work laptop ...
I ran that from the /tools/lib pulled from the repo and also my install point ...
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 19.04
Release: 19.04
Codename: disco

uname -a
Linux drandynisbet-XPS-13-9360 5.0.0-29-generic #31-Ubuntu SMP Thu Sep 12 13:05:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Thanks,
Andy

@yonghong-song
Copy link
Collaborator

yonghong-song commented Sep 25, 2019

@drandynisbet Could you check whether the following change

-bash-4.4$ git diff
diff --git a/src/python/bcc/__init__.py b/src/python/bcc/__init__.py
index 2d6dc350..f3910c6f 100644
--- a/src/python/bcc/__init__.py
+++ b/src/python/bcc/__init__.py
@@ -1355,6 +1355,8 @@ class BPF(object):
         if self.tracefile:
             self.tracefile.close()
             self.tracefile = None
+        for name, fn in list(self.funcs.items()):
+            os.close(fn.fd)
         if self.module:
             lib.bpf_module_destroy(self.module)
             self.module = None
-bash-4.4$

fixed the issue or not?

@drandynisbet
Copy link

Hi - yes fixed it - many many thanks ... although I did remove my build directory - recreate it and reconfigure as there seemed to be multiple copies of init.py in the build directory and some were not updated with the change ...

Cheers,
Andy

yonghong-song added a commit that referenced this pull request Sep 25, 2019
Fix issue #989

When module is cleaned up, let us also close all bpf program
file descriptors to avoid fd leaking.

Signed-off-by: Yonghong Song <[email protected]>
yonghong-song added a commit that referenced this pull request Sep 25, 2019
Fix issue #989

When module is cleaned up, let us also close all bpf program
file descriptors to avoid fd leaking.

Signed-off-by: Yonghong Song <[email protected]>
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

Successfully merging this pull request may close these issues.

None yet

6 participants