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

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
67/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
r
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
R
スター
14
フォーク
9
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Bioconductor/BiocFileCache のほかの issue

Bioconductor/BiocFileCache の issue をすべて見る

似ている issue

R の issue をもっと見る

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

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