Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bcc.BPF.cleanup(): Ensure self.funcs items get deleted during cleanup
Since commit 115b959 ("Fix a file descriptor leak when module is deleted (#2530)"), we observe the following exceptions during python exit: Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/usr/lib/python2.7/dist-packages/bcc/__init__.py", line 1366, in cleanup os.close(fn.fd) OSError: [Errno 9] Bad file descriptor which occurs for python programs issuing a call to 'cleanup()', or using the 'with bcc.BPF(...)' code pattern. BPF's 'cleanup' is registered to be invoked atexit. Alas, commit 115b959 introduced an 'os.close(fn.fd)' call for each func loaded (to prevent accidental FD leakage). Problem is, that the 'self.funcs' dict entries are NOT deleted, making subsequent calls to 'cleanup' to attempt closing the same 'fn.fd' again and again. It is expected from 'cleanup' to operate correctly when called repeatedly; Therefore, it should "nullify" references to closed resources. Fix, by deleting the reference to each unloaded function from the 'self.func' dictionary. Fixes: 115b959 ("Fix a file descriptor leak when module is deleted (#2530)") Reported-by: Dana Rubin <drubin@metanetworks.com> Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
- Loading branch information