gh-105987: Fix reference counting issue in _asyncio._swap_current_task#105989
gh-105987: Fix reference counting issue in _asyncio._swap_current_task#105989kumaraditya303 merged 5 commits intopython:mainfrom chgnrdv:_asyncio-swap_current_task-fix-refcount
_asyncio._swap_current_task#105989Conversation
'_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
carljm
left a comment
There was a problem hiding this comment.
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? |
| Task = getattr(tasks, '_CTask', None) | ||
|
|
||
| def test_issue105987(self): | ||
| code = """if 1: |
There was a problem hiding this comment.
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.
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 <52372310+chgnrdv@users.noreply.github.com>
Fixes #105987
_PyDict_GetItem_KnownHashreturns borrowed reference to previous task object, so call to_PyDict_DelItem_KnownHash/_PyDict_SetItem_KnownHashcan deallocate it before it will be returned fromswap_current_taskfunction_asyncio._swap_current_taskdue to improper reference counting #105987