-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
test_code.test_free_different_thread
is flaky when the GIL is disabled
#117683
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
Labels
Comments
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Apr 9, 2024
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Apr 9, 2024
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Apr 9, 2024
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Apr 12, 2024
colesbury
added a commit
to colesbury/cpython
that referenced
this issue
Apr 15, 2024
colesbury
added a commit
that referenced
this issue
Apr 16, 2024
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This test case checks that freeing a code object on a different thread then where the co_extra was set is safe. However, the test make some assumptions about when destructors are called that aren't always true in the free-threaded build:
cpython/Lib/test/test_code.py
Lines 855 to 875 in fa58e75
In particular, the assertion
self.test.assertEqual(LAST_FREED, 500)
in theThreadTest
occasionally fails becauseLAST_FREED
is stillNone
. The underlying issue is that biased reference counting can delay the calling of the code object's destructor.Normally, the
gc_collect()
calls are sufficient to ensure that the code object is collected. They sort of are -- the code object is being freed -- but it happens concurrently in the main thread and may not be finished by the timeThreadTest
calls theself.test.assertEqual(LAST_FREED, 500)
.The timeline I've seen when debugging this is:
ThreadTest
ThreadTest
deletes the final reference tof
. The total reference count is now zero, but it's represented asob_ref_local=1
,ob_ref_shared=-1
, soTestThread
enqueues it to be merged by the main thread.ThreadTest
callsgc_collect()
and thenself.test.assertEqual(LAST_FREED, 500)
, which fails...
LAST_FREED
to 500.Linked PRs
The text was updated successfully, but these errors were encountered: