Skip to content

Log upstream server errors on metadata fetches by status alone - #751

Open
simonchrz wants to merge 2 commits into
git-pkgs:mainfrom
simonchrz:fix/metadata-5xx-log
Open

simonchrz wants to merge 2 commits into
git-pkgs:mainfrom
simonchrz:fix/metadata-5xx-log

Conversation

@simonchrz

@simonchrz simonchrz commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #745, as suggested there.

upstreamMetadataStatus built a fetch.StatusError for every status other than 200 and 404, so each "metadata fetch failed" log line for an upstream 5xx or 429 carried up to 4 KiB of its error page. Server errors and 429 now return the plain upstream returned N error again, as registries' fetcher keeps StatusError only for the other statuses. 403, 409 and the rest still keep their body, so policy denials are forwarded as before.

TestUpstreamMetadataStatusKeepsServerErrorsShort covers both sides.

Summary by CodeRabbit

  • Bug Fixes
    • Metadata requests that receive an upstream rate-limit or server-error response now show a concise status-based error instead of including the upstream response body.
    • Other non-success metadata responses continue to include their response details.

Since policy denials are forwarded, upstreamMetadataStatus built a
fetch.StatusError for every status, so each failed fetch logged up to
4 KiB of a 5xx or 429 error page. Those return the plain
"upstream returned N" error again, as registries' fetcher does.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 32 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b8a54c77-a4f8-4707-b878-467603996385
Commits

Reviewing files that changed from the base of the PR and between f992cd3 and f61deda.

Files selected for processing: 1

  • internal/handler/metadata_block_test.go

No actionable comments were generated in the recent review.

Walkthrough

The metadata status handler now returns status-only errors for upstream 429 and 5xx responses. Other refusal statuses retain the upstream response body and content type in a fetch.StatusError.

Changes: Metadata status handling

Layer / File(s) Summary
Status error mapping
internal/handler/handler.go, internal/handler/metadata_block_test.go
The handler returns plain status-based errors for 429 and 5xx responses. Tests verify that 403, 409, and 410 responses retain their bodies in fetch.StatusError values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • Issue 744: The PR changes the same status-mapping function, but does not cover the issue’s full request, including serveUpstreamBlock in metadata error branches.

Possibly related PRs

  • git-pkgs/proxy#745: Both PRs change the status-to-error mapping in upstreamMetadataStatus.
  • git-pkgs/proxy#650: Both PRs use fetch.StatusError to preserve upstream policy-denial details, though PR 650 covers artifact downloads.

Suggested labels: bug

Suggested reviewers: andrew

Merge Risk: Minimal · previous review f992c

Upstream 429 and 5xx error pages no longer appear in "metadata fetch failed" logs. Policy-denial forwarding for 403 and 409 is unchanged. No concrete regression was found, and the change is easy to revert.

Security architecture risk: Minimal · up to f992c

The change removes upstream error-page content from rate-limit and server-failure errors without changing which responses succeed. Policy-denial forwarding and rate-limit hold handling remain intact. No introduced or worsened security or failure-containment risk was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The change narrows upstream-controlled data propagation through existing metadata failure paths. It does not make these responses successful or add a new caller, request destination, or authority transition.

Trust Boundaries and Controls

  • observed — Metadata policy-refusal forwarding requires a StatusError with status 403 or 409, neither of which loses its body-bearing representation. Rate-limit hold responses instead require HeldError and retain their Retry-After handling. Removing StatusError from 429 and server failures therefore does not bypass these controls.

Resilience and Maintainability Implications

  • observed — The ordinary metadata fetch path defers response-body closure before status classification, so the new early return retains resource cleanup. Failed responses remain outside the successful cache-write path, and existing recovery does not require a 429 or server-failure StatusError payload.
Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: upstream server errors (5xx and 429) on metadata fetches are now logged by status alone. The raw summary confirms that upstreamMetadataStatus returns a status-only err…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: upstream server errors (5xx and 429) on metadata fetches are now logged by status alone. The raw summary confirms that upstreamMetadataStatus returns a status-only error for 5xx and 429 responses, while other non-200 statuses keep a bounded body. The title is specific, follows the length guidance, and avoids file lists or vague terms.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ccc4c9be-6112-4dea-906a-e6a2b1938da2
Commits

Reviewing files that changed from the base of the PR and between 41c6fb7 and f992cd3.

Files selected for processing: 2

  • internal/handler/handler.go
  • internal/handler/metadata_block_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants