bfcneedsupdate() compares 'expires' by date, so short max-age resources are stale immediately after download

Đang mở
#75 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
67/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
r
Lĩnh vực
backend

Hướng nghiên cứu

Start in R/BiocFileCache-class.R at the bfcneedsupdate() expiry check near line 1024, then inspect its tests for expiry and ETag/Last-Modified behavior. Reproduce with a resource whose max-age is shorter than the time until midnight; the fix is done when it is not marked stale immediately after download and the existing freshness checks still behave correctly.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Problem

bfcneedsupdate() checks expiry by calendar date:

https://github.com/Bioconductor/BiocFileCache/blob/devel/R/BiocFileCache-class.R#L1024

expired <- as.Date(file_expires, optional=TRUE) <= Sys.Date()

expires is set to response time + max-age (since #55). When max-age is shorter than the time left until midnight, the expiry date is today. The check is then TRUE immediately, and because expired short-circuits the ETag/Last-Modified comparison, the resource reports as stale right after download.

bioconductor.org now serves files through Cloudflare with short max-age values, so this affects most Bioconductor-hosted resources:

URL cache-control
packages/stats/bioc/bioc_pkg_stats.tab max-age=300, s-maxage=3600
checkResults/devel/bioc-LATEST/BUILD_STATUS_DB.txt max-age=300, s-maxage=31536000
packages/3.23/bioc/VIEWS max-age=30, s-maxage=31536000

Reprex

BiocFileCache 3.2.0 (release); the same line is in devel 3.3.3.

library(BiocFileCache)
url <- "https://bioconductor.org/packages/stats/bioc/bioc_pkg_stats.tab"
bfc <- BiocFileCache(tempfile(), ask = FALSE)
bfcadd(bfc, rname = url, fpath = url, rtype = "web", action = "copy", download = TRUE)
rid <- bfcquery(bfc, url, "rname", exact = TRUE)$rid
bfcinfo(bfc, rid)$expires   # a few minutes from now, i.e. today
bfcneedsupdate(bfc, rid)    # TRUE, seconds after the download

Impact

Any package that does if (bfcneedsupdate(...)) bfcdownload(...) on these URLs re-downloads them on every call, so the cache does nothing. BiocPkgTools hit this as a test failure on r-universe (seandavi/BiocPkgTools#92) and worked around it in seandavi/BiocPkgTools#93 by doing its own size/ETag/Last-Modified check.

Suggested fix

Compare full timestamps instead of dates, e.g.

expired <- as.POSIXct(file_expires, tz = "GMT", optional = TRUE) <= Sys.time()

It would also be worth considering whether an expired entry should fall through to the ETag / Last-Modified check rather than returning TRUE outright. With max-age=30, a cache that has merely passed max-age is usually still current, and a matching ETag is stronger evidence than expiry.

Ngôn ngữ chính
R
Star
14
Fork
9
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Bioconductor/BiocFileCache

Tất cả issue của Bioconductor/BiocFileCache

Issue tương tự

Thêm issue về R

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.