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
PyAsyncGenASend
objects allocated from freelists may not have their finalizers called
#113753
Comments
Technically this isn't an asyncio issue (it's part of asynchronous generators, which have uses outside asyncio), but I'll allow it. :-) I'm not familiar with the GC infrastructure -- is the solution as simple as arranging to clear the bit when allocating from the free list? |
@gvanrossum - yeah it could be as simple as adding a line like the following (possibly refactored into a function):
to where we allocate from the free-list: Lines 1913 to 1917 in 99854ce
|
Cool, make the PR and CC me. |
Triage: #113754 has been merged, can this be closed? |
@colesbury Is there any worth in backporting this? |
@hugovk, yes I think it can be closed. I went ahead and closed the issue. @gvanrossum The finalizer for |
Bug report
CPython uses freelists to speed up allocation of certain frequently allocated types of objects. CPython also supports finalizers (i.e.,
tp_finalize
) that are only called once, even if the object is resurrected by its finalizer. These two features do not work well together as currently implemented because we don't clear the_PyGC_PREV_MASK_FINALIZED
bit when objects are allocated from free-lists.As far as I can tell, this only affects
PyAsyncGenASend
objects -- I haven't seen other objects that are both allocated from free-lists and usetp_finalize
.The finalizer for
PyAsyncGenASend
(which may issue a warning), may not be called if the object is allocated from a free-list (and already finalized):Test case
The
test(False)
call should issue a warning about unawaited "asend" coroutine. However, the presence of thetest(true)
call will suppress this warning (if uncommented) because it ensures that there is an already-finalized object in the free-list.Linked PRs
The text was updated successfully, but these errors were encountered: