python / python/cpython

__file__ for Some Dynamic Extension Modules has a Broken Refcount

Open
#118,733 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug report

Bug description:

In gh-118532 I was getting crashes when the _testsinglephase module's cached copy of __dict__ was finalized. I worked around it in that PR by doing an unconditional incref, but that introduced a refleak for other cases. At the time, I wasn't able to determine if gh-118532 was the source of the refcount problem or if it only exposed an existing problem.

While working on gh-118157 I narrowed the problem down to the __file__ value in the cached __dict__ and resolved it by interning the string. However, the underlying problem remains: somewhere along the line there seems to be a missing incref.

That needs to be located and fixed, and then the interning can be dropped.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

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

Read gh-118532 and gh-118157 first, focusing on _testsinglephase, the cached dict, and its file value. Reproduce the refcount failure on the CPython main branch, trace where the missing incref occurs, and confirm that the fix works without the workaround's refleak so the interning can be removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.