Repository navigation
Don't read PyPI cooldown upload time from stale JSON API documents - #860
Conversation
When the JSON API fails and the metadata cache falls back to a stale copy, versionInCooldown now returns res.upstreamErr instead of parsing the stale document's upload time. ErrUpstreamNotFound continues to serve the file unchecked, while other upstream errors fail uncached downloads with 502. Fixes git-pkgs#859
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Fixes #859
Root Cause
With
cache_metadataand cooldown enabled,PyPIHandler.versionInCooldownininternal/handler/pypi.goread release upload times fromres.bodyeven whenres.stalewas true. When the upstream JSON API failed (e.g. 404 or 500) and the metadata cache fell back to a stale copy pastmetadata_ttl, the stale copy's upload time decided whether the download was allowed or withheld (and could be written viastoreUploadTime), even though that copy may have come from a previous upstream.Fix
internal/handler/pypi.go, returnres.upstreamErrfrom thereadListedcallback inversionInCooldownwheneverres.staleis true instead of parsing the stale document.res.upstreamErrisErrUpstreamNotFound(404),versionInCooldowncallsseen(nil)and allows the file through unchecked without storing a stale upload time.versionInCooldownreturns the error so uncached downloads fail with 502 (failed to check cooldown).TestPyPICooldownDoesNotUseAStaleDocumentininternal/handler/pypi_digest_test.gocovering both 500 (stale doc outside cooldown -> 502) and 404 (stale doc inside cooldown -> 200 unchecked).Verification
go test -v ./internal/handler -run TestPyPICooldownDoesNotUseAStaleDocument: PASS (2/2 subtests; also verified 10/10 with-count=10)go test -count=1 ./internal/metadata/pypi/...: PASSgo vet ./...: PASSgofmt -w internal/handler/pypi.go internal/handler/pypi_digest_test.go: cleanTestPyPIDownloadIsNotCheckedAgainstAStaleDocumentintermittently flakes on Windows because itstime.NanosecondMetadataTTLcan remain unexpired within a single Windows clock tick (verified to also fail on unmodifiedmainand pass on other runs with-count=5); all other PyPI and cooldown handler tests pass.Summary by CodeRabbit