Skip to content

bpo-44895: libregrtest: refleak check clears types later #28113

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

Merged
merged 1 commit into from
Sep 1, 2021
Merged

bpo-44895: libregrtest: refleak check clears types later #28113

merged 1 commit into from
Sep 1, 2021

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Sep 1, 2021

libregrtest now clears the type cache later to reduce the risk of
false alarm when checking for reference leaks. Previously, the type
cache was cleared too early and libregrtest raised a false alarm
about reference leaks under very specific conditions.

Move also support.gc_collect() outside clear/cleanup functions to
make the garbage collection more explicit.

Co-Authored-By: Irit Katriel [email protected]

https://bugs.python.org/issue44895

libregrtest now clears the type cache later to reduce the risk of
false alarm when checking for reference leaks. Previously, the type
cache was cleared too early and libregrtest raised a false alarm
about reference leaks under very specific conditions.

Move also support.gc_collect() outside clear/cleanup functions to
make the garbage collection more explicit.

Co-Authored-By: Irit Katriel <[email protected]>
@vstinner
Copy link
Member Author

vstinner commented Sep 1, 2021

@iritkatriel: Would you mind to check if this change fix https://bugs.python.org/issue44895 for you? It seems like you are the only one able to reproduce https://bugs.python.org/issue44895 :-)

@iritkatriel
Copy link
Member

checking!

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah!

@vstinner
Copy link
Member Author

vstinner commented Sep 1, 2021

Using the following patch:

diff --git a/Lib/test/libregrtest/refleak.py b/Lib/test/libregrtest/refleak.py
index 096b5381cd..b82f0e6aaa 100644
--- a/Lib/test/libregrtest/refleak.py
+++ b/Lib/test/libregrtest/refleak.py
@@ -126,7 +126,7 @@ def check_rc_deltas(deltas):
         #
         #   [5, 5, 6]
         #   [10, 1, 1]
-        return all(delta >= 1 for delta in deltas)
+        return any(delta >= 1 for delta in deltas)
 
     def check_fd_deltas(deltas):
         return any(deltas)

I reproduce the bug using refleak.py attached to https://bugs.python.org/issue44895:

$ git switch main
$ git apply patch
$ ./python refleak.py 
-- 1 --
beginning 6 repetitions
123456
......
test leaked [-4, 4, -4] references, sum=-4
test leaked [-4, 4, -4] memory blocks, sum=-4

With this PR, refleak.py runs forever:

$ git switch refleak   # This PR
$ git apply patch
$ ./python refleak.py 
(...)
-- 143 --
beginning 6 repetitions
123456
......
-- 144 --
beginning 6 repetitions
123456
......
(...)

@vstinner vstinner merged commit 679cb47 into python:main Sep 1, 2021
@vstinner vstinner deleted the refleak branch September 1, 2021 15:45
sakibguy added a commit to sakibguy/cpython that referenced this pull request Sep 2, 2021
bpo-44895: libregrtest: refleak check clears types later (pythonGH-28113)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants