Skip to content

Commit

Permalink
Fix memory leak in asyncio awaiter tracking
Browse files Browse the repository at this point in the history
Summary: The bug was incorrectly marking a coroutine as awaiting itself, causing a loop which could never be GC'd. This only happened when executing the bytecode `SEND_GEN` which is a specialized variant of `SEND`. This is why this issue may have gone unnoticed in tests - the bug only kicks in after the interpreter has time to adapt bytecodes.

Reviewed By: itamaro, martindemello

Differential Revision: D65434238

fbshipit-source-id: 01e7b0df51c69eb851ba27e22e05bc85dfeb6ff8
  • Loading branch information
jbower-fb authored and facebook-github-bot committed Nov 5, 2024
1 parent 34d2cc3 commit 20d2153
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ dummy_func(
STAT_INC(SEND, hit);
if ((frame->owner == FRAME_OWNED_BY_GENERATOR) &&
(frame->f_code->co_flags & (CO_COROUTINE | CO_ASYNC_GENERATOR))) {
Ci_PyAwaitable_SetAwaiter(receiver, (PyObject *)gen);
Ci_PyAwaitable_SetAwaiter(receiver, (PyObject *) _PyFrame_GetGenerator(frame));
}
_PyInterpreterFrame *gen_frame = (_PyInterpreterFrame *)gen->gi_iframe;
frame->return_offset = oparg;
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 20d2153

Please sign in to comment.