-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-105987: Fix reference counting issue in _asyncio._swap_current_task
#105989
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
gh-105987: Fix reference counting issue in _asyncio._swap_current_task
#105989
Conversation
'_PyDict_GetItem_KnownHash' returns borrowed reference to previous task object, so consequent calls to '_PyDict_DelItem_KnownHash'/'_PyDict_SetItem_KnownHash' can deallocate it before it will be returned from 'swap_current_task' function
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.
Code LGTM. Thanks for finding and fixing! Please add a NEWS entry.
@carljm If you're uncomfortable merging this, can you ask @kumaraditya303 for a review? |
@@ -222,6 +224,23 @@ class PyEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase | |||
class CEagerTaskFactoryLoopTests(EagerTaskFactoryLoopTests, test_utils.TestCase): | |||
Task = getattr(tasks, '_CTask', None) | |||
|
|||
def test_issue105987(self): | |||
code = """if 1: |
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.
You can just copy paste the code here itself no need to run in separate python process right?
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 gives false positive result, at least on my machine. Also I mentioned that it is common idiom to run code that used to crash in subprocess, e. g. to prevent killing of entire test suite in case of regression.
I wasn't, was just waiting for CI signal. But glad to have @kumaraditya303 's review! |
…chgnrdv/cpython into _asyncio-swap_current_task-fix-refcount
Thanks @chgnrdv for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @chgnrdv and @kumaraditya303, I could not cleanly backport this to |
GH-106099 is a backport of this pull request to the 3.12 branch. |
…ap_current_task` (pythonGH-105989). (cherry picked from commit d2cbb6e) Co-authored-by: chgnrdv <[email protected]>
#106099) [3.12] gh-105987: Fix reference counting issue in `_asyncio._swap_current_task` (GH-105989). (cherry picked from commit d2cbb6e) Co-authored-by: chgnrdv <[email protected]>
Fixes #105987
_PyDict_GetItem_KnownHash
returns borrowed reference to previous task object, so call to_PyDict_DelItem_KnownHash
/_PyDict_SetItem_KnownHash
can deallocate it before it will be returned fromswap_current_task
function_asyncio._swap_current_task
due to improper reference counting #105987