iovisor / iovisor/bcc

test py_test_tools_memleak failed with python3

Open
#1,685 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
22.7k
Forks
4.1k
Avg merge
10d 4h
Merged PRs (30d)
3

Description

The test py_test_tools_memleak failed with python3. python2 works fine as expected.
With your bcc installation with python3, the failure can be easily reproduced with
```
[yhs@localhost python]$ pwd
/home/yhs/work/bcc/tests/python
[yhs@localhost python]$ sudo ./test_tools_memleak.py
E/usr/lib64/python3.6/subprocess.py:766: ResourceWarning: subprocess 14520 is still running
ResourceWarning, source=self)
E/usr/lib64/python3.6/subprocess.py:766: ResourceWarning: subprocess 14523 is still running
ResourceWarning, source=self)
/usr/lib64/python3.6/subprocess.py:204: ResourceWarning: unclosed file <_io.BufferedWriter name=4>
for inst in _active[:]:
/usr/lib64/python3.6/subprocess.py:204: ResourceWarning: unclosed file <_io.BufferedReader name=5>
for inst in _active[:]:
...
======================================================================
ERROR: test_aligned_alloc (__main__.MemleakToolTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "./test_tools_memleak.py", line 117, in test_aligned_alloc
self.assertEqual(cfg.leaking_amount, self.run_leaker("aligned_alloc"))
File "./test_tools_memleak.py", line 71, in run_leaker
if "with outstanding allocations" in line:
TypeError: a bytes-like object is required, not 'str'
...
```

After fixing the above byte-object vs. str errors, the failure seems due to
the following piece of code
```
# At this point, memleak.py have already launched application and set
# probes. Sending command to the leaking application to make its
# allocations.
out = p.communicate(input="\n")[0]
```
In python2, you will get `out` as
```
leaking via valloc, 0x604000
[18:12:20] Top 1 stacks with outstanding allocations:
30000 bytes in 1 allocations from stack
[unknown]
[unknown]
[unknown]
```
But in python3, you only get
```
leaking via valloc, 0x604000
```

As a result, python3 failed the test. Is this because subprocess communication change or
what kind of things could trigger such a change. In python3 environment, you will see these
```
[18:12:20] Top 1 stacks with outstanding allocations:
30000 bytes in 1 allocations from stack
[unknown]
[unknown]
[unknown]
```
if you run the standalone process which is associated with subprocess above.

Maybe some python expert could help debug this a little bit more? Thanks!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running tests/python/test_tools_memleak.py under Python 3 and inspect run_leaker alongside the subprocess.communicate call. Compare its captured output with the standalone memleak.py output and verify that the test passes with the expected allocation report under Python 3.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.