pkgutil direct use of zipimport._zip_directory_cache is no longer safe
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
pkgutil directly uses zipimport._zip_directory_cache, in this block:
def iter_zipimport_modules(importer, prefix=''):
dirlist = sorted(zipimport._zip_directory_cache[importer.archive])
since https://github.com/python/cpython/pull/103208 , this is no longer safe, because that made zipimport no longer always refresh the cache on invalidation. I think that if the cache has been invalidated but not accessed 'normally' since then, this direct access attempt can cause a crash as it doesn't trigger a refresh:
E KeyError: '/tmp/dask-scratch-space/scheduler-belyj1dp/myfile.zip'
I observed this in the test suite for dask-distributed - see https://github.com/dask/distributed/issues/8708 - but it seems like a general issue, and @desmondcheongzx asked me to file an issue, so here it is. That test suite hits it in a test that runs async and creates archives under the same name repeatedly, but there are probably other ways to hit this, I guess.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
- gh-121705
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 pkgutil.iter_zipimport_modules 和 issue 中描述的對 zipimport._zip_directory_cache 的直接存取開始;將其與 CPython PR 103208 引入的快取失效行為進行比較。重現 dask-distributed issue 8708 中的重複封存檔情境,並驗證由此產生的 KeyError 不再發生。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100