Repository navigation
Conversation
- `fetch_api_file` touches the cached `*.jws.json` to now after every check and revalidates with `curl --time-cond`. A body fetched from a stale CDN edge ends up with an mtime newer than the real object's `Last-Modified`, so the server answers `304` until the next publish. - Save the ETag to `<file>.etag` and send `--etag-compare` when one is saved, as `Homebrew::API.fetch_json_api_file` does in Homebrew#24193. Fall back to `--time-cond` without a saved ETag or on curl older than 7.68.0, which lacks `--etag-save` and `--etag-compare`. - curl blanks the `--etag-save` file on a `304` and on an untagged `200`, so save to `<file>.etag.new`, replace `<file>.etag` only when it is non-empty and delete it after a non-`304` without an ETag. This keeps `.etag` in sync with whatever body `brew update` wrote. - Keep the current OS's `.etag` when removing other OS versions' API files.
8 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on Homebrew#24193 (base is that PR's branch,
api-revalidate-stale-cache). Opened on the fork only, because Homebrew allows one AI-assisted PR at a time; it will be retargeted to Homebrew/brew once Homebrew#24193 merges.brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Disclosure: drafted with Claude Code (Opus 5.5); diff and behaviour reviewed by me
Follow-up to Homebrew#24193, which fixes the same mtime/If-Modified-Since problem in the Ruby API path (
Homebrew::API.fetch_json_api_file); this PR does the same forbrew update's bash fetch.fetch_api_fileincmd/update.shdownloadsinternal/packages.<tag>.jws.jsonwithcurl --time-cond <cache file>and thentouches the file. If that body came from a stale CDN edge, its mtime is newer than the real object'sLast-Modified, so every laterbrew updatesends anIf-Modified-Sincethe server answers with304and the stale index stays until the next publish. It also never writes the<file>.etagthat Homebrew#24193 revalidates with, so afterbrew updatewrites a new body the Ruby path compares against an ETag for a different body.This:
--etag-compare <file>.etagwhen an ETag is saved and curl is 7.68.0 or newer (--etag-save/--etag-compareneed 7.68.0; Homebrew only requires 7.41.0), and falls back to--time-condotherwise<file>.etag.newand only replaces<file>.etagwhen it is non-empty, because curl blanks the--etag-savefile on a304and on an untagged200; after a non-304without an ETag (read from--write-out '%{http_code}') the old.etagis deleted.etagwhen removing other OS versions' API files (brew cleanup --scrubkeeps it in api: revalidate JSON API caches with ETag, not the bumped mtime聽Homebrew/brew#24193)The
--time-condpath, the exit 56 retry and the byte-size update detection are unchanged.Repro (the mechanism, without needing a stale edge):
Checked against real curl 8.7.1 and a local server that sends an ETag, honours
If-None-Matchand keepsLast-Modifiedolder than the local mtime (so--time-condalone would304):With
--time-condonly (curl < 7.68.0), run 3 answers304and keeps the old body, which is the current behaviour.馃 Generated with Claude Code
https://claude.ai/code/session_01XdswxjrNLFURYY68A6ZUSi