weakrefobject.c: binary, ternary, or comparison operations ref leak with dead proxy
オープン
まだ誰も着手していません。
extension-modules
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
Original gist: https://gist.github.com/devdanzin/f7d0c7694b2be2345f4cf85f4eedc3ee
Summary
When first
UNWRAP(x)succeeds but secondUNWRAP(y)fails (dead proxy),x's new reference is leaked. Affects ~20 binary operators (+, -, *, /, |, &, ^, etc.).Reproducer
import weakref, sys, gc class C: def __add__(self, other): return NotImplemented def __radd__(self, other): return NotImplemented obj = type('D', (), {})() dead = weakref.proxy(obj) del obj; gc.collect() live_obj = C() live = weakref.proxy(live_obj) before = sys.gettotalrefcount() for i in range(10000): try: live + dead except ReferenceError: pass after = sys.gettotalrefcount() print(f"Leaked {after - before} refs (~{(after-before)//10000}/call)")
Actually, ternary, or comparison operations have the same problem.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-153059
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
weakrefobject.c から開始し、提供された refcount reproducer を CPython main build で実行します。報告で説明されている二項、三項、比較演算のパスを確認します。dead-proxy のケースで参照がリークしなくなり、reproducer の繰り返しループも含めて問題が再現しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100