Repository navigation
Numerous refleaks on main #103879
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error3.12only security fixesonly security fixes
on Apr 26, 2023 The failure on
test.test_htmlparserbisects toef25febcf2ede92a03c5ea00a13e167e0b5cb274 is the first bad commit commit ef25febcf2ede92a03c5ea00a13e167e0b5cb274 Author: Carl Meyer <carl@oddbird.net> Date: Tue Apr 25 11:45:51 2023 -0600 gh-87729: specialize LOAD_SUPER_ATTR_METHOD (#103809)Given that refleak buildbots passed on #103882, it seems this is fixed now.
- moved this from Todo to Done in Release and Deferred blockers 🚫
on Apr 26, 2023 Thanks @JelleZijlstra for fixing!
No problem!
https://buildbot.python.org/all/#/release_status is still red but I assume the buildbots are running now. Given that the refleak buildbots were green on my PR, we probably did fix the issue.
- moved this from Done to In Progress in Release and Deferred blockers 🚫
on Apr 27, 2023 I wasn't able to reproduce the new leak locally (tried both MacOS and Linux). It seems to happen only on one buildbot.
The leak of
test_importis still visible on that buildbot, and the issue persists for a long timeVisible at
https://buildbot.python.org/all/#/builders/205/builds/696
... (note: logs will be cleared for old tests, soon the log will not be visible)Usually, rerunning the tests will let it pass. (Warning, no errors)
I suspect something changed in the test environment.
It seems to happen only on one buildbot.
This is not true.
test_importleaked on the first run and passed in the second run. Visible on various arch*os combinations.https://buildbot.python.org/all/#/builders/766/builds/770
https://buildbot.python.org/all/#/builders/474/builds/1161
https://buildbot.python.org/all/#/builders/411/builds/1216
https://buildbot.python.org/all/#/builders/802/builds/814
https://buildbot.python.org/all/#/builders/210/builds/1196
https://buildbot.python.org/all/#/builders/18/builds/1233
https://buildbot.python.org/all/#/builders/409/builds/1169...
@JelleZijlstra I can reproduce it with
./python -m test -j1 -R 3:3 test_importSingle processing will not cause leakage.
-jis necessary.Good catch, that reproduces it for me too.
Current status:
Found most leakage is from
test_import.SinglephaseInitTests.ref change of type dict: +7 ref change of type float: +21 ref change of type getset_descriptor: +5 ref change of type int: +16 ref change of type str: ... (immortal str not counted) ref change of type tuple: +7 ref change of type type: +12 ref change of type weakref.ReferenceType: +5I took a quick look,
ref change of type type: +12contains many instances created bystate->error = PyErr_NewException("_testsinglephase.error", NULL, NULL);
Modules/_testsinglephase.c:init_moduleis called several times during-jtests, but only once with the single-threaded one.cpython/Modules/_testsinglephase.c
Lines 125 to 148 in 738c226
static int init_module(PyObject *module, module_state *state) { if (PyModule_AddObjectRef(module, "error", state->error) != 0) { return -1; } if (PyModule_AddObjectRef(module, "int_const", state->int_const) != 0) { return -1; } if (PyModule_AddObjectRef(module, "str_const", state->str_const) != 0) { return -1; } double d = _PyTime_AsSecondsDouble(state->initialized); PyObject *initialized = PyFloat_FromDouble(d); if (initialized == NULL) { return -1; } if (PyModule_AddObjectRef(module, "_module_initialized", initialized) != 0) { return -1; } return 0; } At least, I found
initializedis leaked here.PyModule_AddObjectRefcreates a new reference. The previous leak statistics indicatestate->errormay also be leaked elsewhere.@ericsnowcurrently Can you please take a look since the last change is yours?
Reacted by Eric Snow@ericvsmith I tracked down the problem. Hope you can fix it and add me as a co-author.
1
initializedis leaked as mentioned above.2
_testsinglephase_with_statemodule. Itsmd_stateis not released by_testinternalcapi.clear_extensionor_clear_globals.When I manually add and call the clean-up function. Ref leaks are gone.
3
cpython/Lib/test/test_import/__init__.py
Lines 2458 to 2462 in 738c226
# Start with an interpreter that gets destroyed right away. base = self.import_in_subinterp(postscript=''' # Attrs set after loading are not in m_copy. mod.spam = 'spam, spam, mash, spam, eggs, and spam' ''') No cleanup was made against
base, which is leaking ref. This line looks intentional from the comment, but it does leak things.
Most of the ref leaks in
test_importare here. Hopefully, it should be all.@sunmy2019, there are known refleaks in test_import. See gh-102251. Are you talking about more than that?
Also, your analysis is helpful. Thanks!
Are you talking about more than that?
Yes, I am talking about
test_import. The link you give seems to betest_imp.The ref leak in
test_importis introduced at least two months ago:
https://buildbot.python.org/all/#/builders/205/builds/696and still visible and reproducible on
main:./python -m test -j1 -R 3:3 test_import
The above guide should help you clear major ref leaks in
test_import.The tests in question were moved from test_imp to test_import.
Reacted by sunmy2019I think the main refleaks are fixed now, closing this as the
test_importrefleaks are tracked in #102251.- moved this from In Progress to Done in Release and Deferred blockers 🚫
on May 12, 2023
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
https://buildbot.python.org/all/#/release_status shows that the refleak buildbots are failing on current main. Example output on https://buildbot.python.org/all/#/builders/75/builds/745/steps/5/logs/warnings__111_.
Failing tests:
Details
I saw similar leaks triggering the refleak buildbots on #103866 and #103764, before I realized the issue was probably on main.
Based on @sunmy2019's work in #103764 (comment), we're likely leaking references to the
object.__setattr__wrapper descriptor.Linked PRs