Skip to content

gh-154791: Fix asyncio Future losing traceback on repeated result() call - #154798

Open
iaroslavkrasikov wants to merge 3 commits into
python:mainfrom
iaroslavkrasikov:main
Open

gh-154791: Fix asyncio Future losing traceback on repeated result() call#154798
iaroslavkrasikov wants to merge 3 commits into
python:mainfrom
iaroslavkrasikov:main

Conversation

@iaroslavkrasikov

Copy link
Copy Markdown

PR #30274 fixed repeating traceback frames in asyncio.Future by storing tracebacks separately from exceptions in fut_exception_tb. However, it also added Py_CLEAR(fut->fut_exception_tb) in future_get_result() after the first result() call. This means any subsequent await/result() raises with PyException_SetTraceback(exc, None), losing traceback frames.

The _PyFuture implementation never clears _exception_tb and has always behaved correctly. This change makes the C implementation match.

The reference cycle concern motivating the Py_CLEAR is already covered: fut_exception_tb is registered in FutureObj_traverse, so GC can collect any cycle through it.

@python-cla-bot

python-cla-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant