python / python/cpython

Need to keep traceback alive in WITH_EXCEPT_START

Open
#130,595 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3.13 3.14 3.15 interpreter-core type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Currently in WITH_EXCEPT_START the interpreter loop gets the traceback from the exception object and then immediately decref's it before calling the __exit__ function. But the __exit__ function may not incref the traceback (if it's not an interpretedPython function) and could cause the traceback to be replaced on the exception, leading it holding onto a freed traceback.

CPython versions tested on:

CPython main branch, 3.12

Operating systems tested on:

Linux

Linked PRs
  • gh-130562
  • gh-130626

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review linked PRs gh-130562 and gh-130626 first, then locate the WITH_EXCEPT_START interpreter-loop implementation in CPython. Verify the traceback remains valid while exit runs and add or update coverage for the reported replacement and lifetime scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.