You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The maximum sum() of these list is around 5 on 10 runs: not every run leaks a memory block. It looks more like a internal cache which is "unstable" if you look at the number of allocated memory blocks.
I wrote PR 12743 to modify _abc: use weakref.WeakSet rather than using directly a set of weak references. With this PR, calling _get_dump() should clear all broken weak references. I'm not sure if it's really useful for this specific issue, since dash_R_cleanup() calls obj._abc_caches_clear() on all abstract base classes (ABC): all caches must be removed before reading the total number of allocated memory blocks (sys.getallocatedblocks()).
Using this patch, at least the following tests fail:
test_asyncio
test_code
test_collections
test_contextlib
test_contextlib_async
test_ctypes
test_functools
test_multiprocessing_forkserver
test_multiprocessing_spawn
test_regrtest
test_statistics
test_typing
test_xml_etree_c
I didn't analyze why yet. I guess that they are not real memory leaks, but more minor issue in the code checking for memory leaks. Sadly, it seems like such small glitch can cause a whole Refleak buildbot worker to fail :-(
@victor, with your patch applied, for test_typing (locally, Windows x64):
$ ./python -m test test_typing -R 3:20
Different result on every run (race condition maybe?)
$ ./python -m test test_typing -R 1:20
Same result as yours on every run.
Activity
vstinner commentedon Apr 8, 2019
Sometimes, each run of test_functools leaks exactly 1 memory block, even when the whole test is "re-run in verbose mode". Sometimes, it doesn't leak.
https://buildbot.python.org/all/#/builders/80/builds/550
test_functools leaked [1, 1, 1] memory blocks, sum=3
Re-running test 'test_functools' in verbose mode
test_functools leaked [1, 1, 1] memory blocks, sum=3
Maybe the problem comes from
Example on Linux:
== Tests result: FAILURE ==
7 tests OK.
1 test failed:
test_functools
Total duration: 8 sec 333 ms
Tests result: FAILURE
vstinner commentedon Apr 8, 2019
Current bisection progress: I'm able to reproduce a failure with attached test_functools.py (211 lines) using:
./python -m test -F -j5 -R 3:3 test_functools
It takes between 4 and 200 runs to reproduce the failure, I don't understand what triggers the bug.
I failed to identify if the bug is more likely when the system is idle or when the system is busy. It looks purely random.
vstinner commentedon Apr 8, 2019
Some progress.
I'm now able to reproduce the issue with attached test_functools2.py (103 lines, a single test method):
$ cp (...)test_functools2.py Lib/test/ $ ./configure -C --with-pydebug CFLAGS=-O0 $ make $ ./python -m test -F -j5 -R 3:3 test_functools2 (...) 0:00:02 load avg: 0.95 [ 19/1] test_functools failed beginning 6 repetitions 123456 ...... test_functools leaked [1, 1, 1] memory blocks, sum=3 (...) Tests result: FAILUREI disabled the C accelerator _functools.
I'm now trying to disable the C accelerator of abc, but I had a small issue: bpo-36565.
vstinner commentedon Apr 8, 2019
The issue comes maybe from the complex code in Lib/test/libregrtest/refleak.py to handle the ABC cache:
...
vstinner commentedon Apr 9, 2019
This issue isn't a real memory leak: if I use -R 3:10 instead of -R 3:3, the test doesn't fail anymore.
But the issue is still annoying since it makes Refleaks buildbot workers fail randomly :-/
This issue remembers me the unstable multiprocessing tests:
Patch to always display memory allocations differences:
Truncated output with the patch:
vstinner@apu$ ./python -m test -F -r -j1 -R 3:10 test_functools
Using random seed 4308771
Run tests in parallel using 1 child processes
0:00:04 load avg: 0.91 [ 1] test_functools passed
[0, 1, 2, 0, 0, 0, 0, 0, 0, 0]
...
0:00:13 load avg: 0.92 [ 3] test_functools passed
[2, 1, 0, 0, 0, 0, 0, 0, 0, 0]
...
0:00:17 load avg: 0.93 [ 4] test_functools passed
[0, 3, 0, 0, 0, 0, 0, 0, 0, 0]
...
0:00:21 load avg: 0.93 [ 5] test_functools passed
[0, 1, 0, 0, 2, 0, 0, 0, 0, 0]
...
0:00:26 load avg: 0.93 [ 6] test_functools passed
[0, 4, 0, 0, 0, 0, 0, 0, 0, 0]
...
0:00:34 load avg: 0.87 [ 8] test_functools passed
[0, 1, 0, 2, 0, 0, 0, 0, 0, 0]
...
0:01:06 load avg: 1.15 [ 15] test_functools passed
[0, 1, 0, 2, 0, -1, 1, 0, 0, 0]
...
0:01:10 load avg: 1.46 [ 16] test_functools passed
[0, 4, 0, 0, 0, 0, 0, 0, -1, 1]
...
The maximum sum() of these list is around 5 on 10 runs: not every run leaks a memory block. It looks more like a internal cache which is "unstable" if you look at the number of allocated memory blocks.
vstinner commentedon Apr 9, 2019
I wrote PR 12743 to modify _abc: use weakref.WeakSet rather than using directly a set of weak references. With this PR, calling _get_dump() should clear all broken weak references. I'm not sure if it's really useful for this specific issue, since dash_R_cleanup() calls obj._abc_caches_clear() on all abstract base classes (ABC): all caches must be removed before reading the total number of allocated memory blocks (sys.getallocatedblocks()).
serhiy-storchaka commentedon Apr 9, 2019
_abc was written for optimization. Your PR makes it using slower Python code. Could you please test how much this hits the performance of abc?
vstinner commentedon Apr 9, 2019
If I modify libregrtest with the following patch:
And I add the following file Lib/test/test_noop.py:
regrtest detects a "leak":
$ ./python -m test -R 3:3 test_noop Run tests sequentially 0:00:00 load avg: 0.55 [1/1] test_noop beginning 6 repetitions 123456 ...... test_noop leaked [0, 1, 0] memory blocks, sum=1 test_noop failed== Tests result: FAILURE ==
1 test failed:
test_noop
Total duration: 113 ms
Tests result: FAILURE
The issue comes from this look in Lib/test/libregrtest/refleak.py:
Because of "if i >= nwarmup:", get_pooled_int() isn't call during "warmup", whereas the purpose of the warmup is to warmup *everything*.
Maybe get_pooled_int() allocates one frame object and keeps it alive in its "zombi frame". Maybe something else is allocated and kept alive.
Anything, removing "if i >= nwarmup:" to always compute deltas fix this specific issue.
Attached PR 12744 fix this bug.
vstinner commentedon Apr 9, 2019
New changeset 5aaac94 by Victor Stinner in branch 'master':
bpo-36560: Fix reference leak hunting in regrtest (GH-12744)
5aaac94
vstinner commentedon Apr 9, 2019
New changeset 9c14061 by Victor Stinner in branch '2.7':
bpo-36560: Fix reference leak hunting in regrtest (GH-12744) (GH-12745)
9c14061
vstinner commentedon Apr 9, 2019
New changeset bb44478 by Victor Stinner in branch 'master':
bpo-36560: regrtest: don't collect the GC twice (GH-12747)
bb44478
vstinner commentedon Apr 9, 2019
I mostly wrote PR 12743 to debug this issue. Please see the discussion directly on the PR ;-)
vstinner commentedon Apr 9, 2019
New changeset 86f0354 by Victor Stinner in branch '3.7':
[3.7] bpo-36560: regrtest: don't collect the GC twice (GH-12747) (GH-12749)
86f0354
vstinner commentedon Apr 11, 2019
Patch making check on memory block leaks stricter:
Using this patch, at least the following tests fail:
I didn't analyze why yet. I guess that they are not real memory leaks, but more minor issue in the code checking for memory leaks. Sadly, it seems like such small glitch can cause a whole Refleak buildbot worker to fail :-(
vstinner commentedon Apr 17, 2019
Another example:
AMD64 Fedora Rawhide Refleaks 3.6
https://buildbot.python.org/all/#/builders/193/builds/5
test_contextlib leaked [8, 1, 1] memory blocks, sum=10
I cannot reproduce the issue on my ("idle") laptop. It sounds like a random failure (race condition).
vstinner commentedon Sep 24, 2019
Recent fail on AMD64 Fedora Rawhide Refleaks 3.x:
https://buildbot.python.org/all/#builders/189/builds/162
test_functools leaked [1, 2, 1] memory blocks, sum=4
vstinner commentedon Jun 11, 2020
AMD64 Fedora Rawhide Refleaks 3.8:
https://buildbot.python.org/all/#/builders/79/builds/196
test_functools leaked [1, 1, 1] memory blocks, sum=3
vstinner commentedon May 26, 2021
I didn't see this failure recently. I close the issue.
vstinner commentedon Aug 31, 2021
Recent failure on AMD64 Fedora Rawhide Refleaks 3.x:
https://buildbot.python.org/all/#/builders/565/builds/131
test_typing leaked [1, 1, 1] memory blocks, sum=3
(...)
0:46:40 load avg: 0.00 Re-running test_typing in verbose mode
test_typing leaked [1, 1, 1] memory blocks, sum=3
I don't reopen the issue since I failed to reproduce it.
vstinner commentedon Aug 31, 2021
I can see the test_typing issue with this patch:
Examples:
Fidget-Spinner commentedon Aug 31, 2021
@victor, with your patch applied, for test_typing (locally, Windows x64):
vstinner commentedon Jul 1, 2024
I fixed another test_functools random leak with the PR #121191.