Uh oh!
There was an error while loading. Please reload this page.
gh-140431: Fix GC crash due to partially initialized coroutines - #140470
Conversation
The `make_gen()` function creates and tracks generator/coro objects, but doesn't fully initialize all the fields. At a minimum, we need to initialize all the fields that may be accessed by gen_traverse because the call to `compute_cr_origin()` can trigger a GC.
For what it's worth, with this patch, I am no longer able to reproduce the bug. With this patch, I was not able to reproduce the bug after an hour of running the tests. Without this patch, the segfault occurs on average after < 4 minutes. I have used the following script to check: Details#!/usr/bin/env bashset -e
time_start=$(date +%s)
git clean -dfx
CC=clang CXX=clang++ ./configure --with-address-sanitizer --with-pydebug --disable-gil
make -j12
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
./python -X dev -m test -R 9:9 test_asyncio.test_free_threading
time_end=$(date +%s)
delta=$((time_end - time_start))
minutes=$((delta /60))
seconds=$((delta %60))echoechoecho"Elapsed time: ${minutes}m ${seconds}s"echoecho -n "Possibly good commit: "
git rev-parse HEAD
git log --oneline | head -n 1
echo |
efimov-mikhail
left a comment
There was a problem hiding this comment.
LGTM.
We definitely need to set correct value of gen->gi_iframe.f_executable in make_gen.
Uh oh!
There was an error while loading. Please reload this page.
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…pythongh-140470) The `make_gen()` function creates and tracks generator/coro objects, but doesn't fully initialize all the fields. At a minimum, we need to initialize all the fields that may be accessed by gen_traverse because the call to `compute_cr_origin()` can trigger a GC. (cherry picked from commit 574405c) Co-authored-by: Sam Gross <colesbury@gmail.com>
GH-140504 is a backport of this pull request to the 3.14 branch. |
bedevere-bot
commented
Oct 23, 2025
|
gh-140470) (gh-140504) The `make_gen()` function creates and tracks generator/coro objects, but doesn't fully initialize all the fields. At a minimum, we need to initialize all the fields that may be accessed by gen_traverse because the call to `compute_cr_origin()` can trigger a GC. (cherry picked from commit 574405c) Co-authored-by: Sam Gross <colesbury@gmail.com>
…pythongh-140470) The `make_gen()` function creates and tracks generator/coro objects, but doesn't fully initialize all the fields. At a minimum, we need to initialize all the fields that may be accessed by gen_traverse because the call to `compute_cr_origin()` can trigger a GC.
The
make_gen()function creates and tracks generator/coro objects, but doesn't fully initialize all the fields. At a minimum, we need to initialize all the fields that may be accessed by gen_traverse because the call tocompute_cr_origin()can trigger a GC.