python / python/cpython

pkgutil direct use of zipimport._zip_directory_cache is no longer safe

Aperta
#121,342 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con pkgutil.iter_zipimport_modules e con l’accesso diretto a zipimport._zip_directory_cache descritto nell’issue; confrontalo con il comportamento di invalidazione della cache introdotto da CPython PR 103208. Riproduci lo scenario di archivio ripetuto dell’issue 8708 di dask-distributed e verifica che il KeyError risultante non si verifichi più.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.