pkgutil direct use of zipimport._zip_directory_cache is no longer safe
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với pkgutil.iter_zipimport_modules và quyền truy cập trực tiếp vào zipimport._zip_directory_cache được mô tả trong issue; so sánh với hành vi vô hiệu hóa bộ nhớ đệm được giới thiệu bởi CPython PR 103208. Tái hiện kịch bản archive lặp lại từ dask-distributed issue 8708 và xác minh rằng KeyError phát sinh sau đó không còn xảy ra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 30/100