-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-44353: Fix memory leak introduced by #27262 #27305
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
Conversation
@pablogsal This should fix memory leak introduced by #27262 And could you please add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct, you are returning a new object without incrementing the refcount, this will crash surely
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@uriyyo, look at #27262 (review) |
Hmm, I will try to investigate where memory leak is. |
@ambv Thanks for comment. Did forget about it. |
@pablogsal @ambv I have found were the memory leak is, that's not because of C extension, sorry about confusing with me first comment. Memory leak was because of inner This lines lead to memory leak: cpython/Lib/test/test_typing.py Lines 3723 to 3727 in a4760cc
I fixed this issue by clearing cache after test execution. |
I have made the requested changes; please review again |
Thanks for making the requested changes! @pablogsal: please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed locally this fixes the refleaks.
Without the change:
❯ ./python.exe -m test test_typing -R :
+ cd cpython
+ shift
+ PYTHONWARNINGS=
+ PYTHONSTARTUP=
+ IN_REGRTEST=1
+ ./python.exe -E -Wd -m test test_typing -R :
0:00:00 load avg: 1.99 Run tests sequentially
0:00:00 load avg: 1.99 [1/1] test_typing
beginning 9 repetitions
123456789
.........
test_typing leaked [220, 220, 220, 220] references, sum=880
test_typing leaked [68, 68, 68, 68] memory blocks, sum=272
test_typing failed (reference leak)
== Tests result: FAILURE ==
1 test failed:
test_typing
1 re-run test:
test_typing
Total duration: 5.6 sec
Tests result: FAILURE
After the change:
❯ ./python.exe -m test test_typing -R :
+ cd cpython
+ shift
+ PYTHONWARNINGS=
+ PYTHONSTARTUP=
+ IN_REGRTEST=1
+ ./python.exe -E -Wd -m test test_typing -R :
0:00:00 load avg: 2.03 Run tests sequentially
0:00:00 load avg: 2.03 [1/1] test_typing
beginning 9 repetitions
123456789
.........
== Tests result: SUCCESS ==
1 test OK.
Total duration: 5.5 sec
Tests result: SUCCESS
@@ -3692,10 +3692,15 @@ def test_c_functions(self): | |||
|
|||
|
|||
class NewTypeTests: | |||
def cleanup(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: this is different from BaseTestCase.clear_caches because here we use self.module
instead of hard-coded typing
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, great investigating @uriyyo! I forgot that the global typing
and the py_typing
used for NewType
tests are different module objects. I was quite puzzled for a while about why the BaseTestCase
clearing didn't work :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fidget-Spinner I spent a lot of time investigating C code because though that problem was at it, but actual problem was at test code)
It was tricky but interesting to investigate this memory leak)
@@ -3692,10 +3692,15 @@ def test_c_functions(self): | |||
|
|||
|
|||
class NewTypeTests: | |||
def cleanup(self): | |||
for f in self.module._cleanups: | |||
f() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those seem to be cleaning LRU caches for various type __getitem__
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, and it clears Union.__getitem__
cache which lead to memory leak.
https://bugs.python.org/issue44353