Skip to content

Conversation

@savannahostrowski
Copy link
Member

@savannahostrowski savannahostrowski commented Nov 6, 2025

So after spelunking here it appears that the issue here is that we can't clear frame->previous after _PyFrame_ClearExceptCode in clear_gen_frame because _PyFrame_ClearExceptCode calls take_ownership which copies the frame with a stale previous pointer. This makes f_back point to the caller, instead of None.

@savannahostrowski
Copy link
Member Author

@markshannon Are you still the right person to take a look at this 😄 ?

@savannahostrowski savannahostrowski deleted the reference-cycle branch December 4, 2025 22:59
@savannahostrowski savannahostrowski restored the reference-cycle branch December 4, 2025 22:59
@kumaraditya303
Copy link
Contributor

I came across this bug today while writing an asyncio test and this fixed it.

ping @markshannon for review

Copy link
Member

@markshannon markshannon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix

@savannahostrowski savannahostrowski enabled auto-merge (squash) December 17, 2025 18:52
@savannahostrowski savannahostrowski merged commit 92243dc into python:main Dec 17, 2025
52 checks passed
@miss-islington-app
Copy link

Thanks @savannahostrowski for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 17, 2025
…ythonGH-141112)

(cherry picked from commit 92243dc62ce10715ab0d9074b23dea5a1bfa9dcc)

Co-authored-by: Savannah Ostrowski <[email protected]>
@miss-islington-app
Copy link

Sorry, @savannahostrowski, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 92243dc62ce10715ab0d9074b23dea5a1bfa9dcc 3.13

@bedevere-app
Copy link

bedevere-app bot commented Dec 17, 2025

GH-142902 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Dec 17, 2025
savannahostrowski added a commit that referenced this pull request Dec 17, 2025
…H-141112) (#142902)

GH-100964: Fix reference cycle in exhausted generator frames (GH-141112)
(cherry picked from commit 92243dc)

Co-authored-by: Savannah Ostrowski <[email protected]>
savannahostrowski added a commit that referenced this pull request Dec 17, 2025
…G… (#142904)

* [3.13] GH-100964: Fix reference cycle in exhausted generator frames (GH-141112)
(cherry picked from commit 92243dc)

Co-authored-by: Savannah Ostrowski <[email protected]>
@kumaraditya303 kumaraditya303 removed the needs backport to 3.13 bugs and security fixes label Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants