python / python/cpython

pkgutil direct use of zipimport._zip_directory_cache is no longer safe

オープン
#121,342 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。