`arraymodule`, `_decimal`: possible lazy import caches reference leaks in free-threaded builds
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug description:
As pointed out by @htjworld in https://github.com/python/cpython/pull/148088#issuecomment-4196296604:
I was wondering about the lazy init pattern in a free-threaded build. If two threads enter
build_struct_timeconcurrently withst->time_struct_time == NULL, both would callPyImport_ImportModuleAttrStringand one overwrite would leave a reference with an incremented refcount that never gets decref'd.
I noticed
arraymodule.cand_decimal.chave the same pattern, so maybe this is just accepted. But _asynciomodule.c initializes eagerly in module_init() which avoids this structurally. Was lazy chosen deliberately here over eager init in init_state()?
While I've addressed this in #148088, I think that this is a valid concern, and import caches should use CAS, just like:
If there's interest, I can do it.
(It seems similar to #149000, so perhaps a more thorough check warranted.)
CPython versions tested on:
CPython main branch
Operating systems tested on:
macOS
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先比较 arraymodule.c 和 _decimal.c 中的延迟初始化与 _asynciomodule.c 中的急切初始化,以及 Modules/_sre/sre.c 中的 CAS 模式。检查 free-threaded 路径中的并发初始化和引用泄漏;当受影响的导入缓存能够在该并发模式下安全运行,且相关行为已由验证覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100