Revalidate checksums of stale Maven metadata in virtual registries
What does this MR do and why?
Fix: the Maven virtual registry now sends .sha1 and .md5 requests upstream when the parent maven-metadata.xml entry is stale.
Bug: handle_digest_request in VirtualRegistries::Packages::Maven::HandleFileRequestService returned the stored checksum without checking if the cache entry was stale. When maven-metadata.xml refreshed, a client could get a checksum that did not match the XML it just downloaded. Maven rejects that file. The customer hit this right after the stale entry was purged.
Change: a new private method, stale_remote_metadata?(entry), is true when the entry is remote, its path ends with maven-metadata.xml, and stale? is true. For those entries, the digest request takes the existing upstream branch. It sends the upstream digest through Workhorse (workhorse_send_url) and queues CreateCacheEntryWorker to refresh the cached file.
- Scope: only stale remote
maven-metadata.xmlchecksums. Fresh metadata, other files, and local upstream entries are unchanged. - Cost: these requests go upstream at most once per artifact per
metadata_cache_validity_hourswindow (default 24h). Checksum files are tiny. - Upstream down: if no upstream answers, for example a timeout, the service still returns the stored digest. That digest matches the cached file.
Why no feature flag
This is a small bug fix. The worst case is one extra small upstream fetch per checksum file per day. There are no database, UI, or API changes.
Independent MRs: this is MR 2 of 2 for the issue. MR 1 makes a stale maven-metadata.xml download again even when the ETag matches. Either MR can merge first.
References
- Issue: #604701
- MR 1: !259434
- Artifact Registry parity: gitlab-org/ops/artifact-registry#1519. AR already revalidates its checksum sidecars, so only the metadata part applies there.
Screenshots or screen recordings
Not applicable. There are no UI changes.
How to set up and validate locally
- Configure a Maven virtual registry with an upstream, such as Maven Central.
- Pull
.../maven-metadata.xmland.../maven-metadata.xml.sha1through the virtual registry. - In the Rails console, set that cache entry's
upstream_checked_atto a year ago. - Request the
.sha1file again. - Check the response. It comes from upstream (Workhorse send-url). It is no longer the stored digest.
Tests: the new context "when the cache entry is a stale maven-metadata.xml" runs for both md5 and sha1. It checks that the request returns workhorse_send_url, queues the refresh job, and returns the stored digest when the upstream times out. 4 of these examples fail on master. The full spec file passes (73 examples). RuboCop is clean.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.