Skip to content

Imports: fail at once on an oversized document, a refused target or endless redirects - #921

Open
schmitch wants to merge 1 commit into
mainfrom
claude/777-import-permanent-fetch-errors
Open

schmitch wants to merge 1 commit into
mainfrom
claude/777-import-permanent-fetch-errors

Conversation

@schmitch

Copy link
Copy Markdown
Member

Fixes #777

Problem

The import's clients turn the upstream client's errors into a SourceError with SourceError::of (crates/server/src/import/feed.rs). It mapped everything but a status to Unreachable, which is transient. So a document larger than proxy.max_metadata_bytes, a link-local / cloud-metadata target and a redirect that does not end made the preflight answer 502 "the source is unreachable", and the worker read the same document four times (with its backoff) before it failed. Nothing said what to change.

Change

  • SourceError::of maps TooLarge, MetadataTarget and TooManyRedirects to SourceError::Invalid, which is permanent. Transport and Io stay Unreachable; the match is exhaustive now, so a new UpstreamError has to be classified.
  • The messages say what to do:
    • <url> is larger than the <limit> bytes Forge reads of a metadata document; raise proxy.max_metadata_bytes to read it
    • for npm's /-/all (SourceError::of_listing), the same with , or name the packages or scopes to import instead
    • <url> is a link-local or cloud-metadata address, which Forge does not request
    • <url> redirects more than <max> times; give the URL the source answers at
  • One mapping serves the NuGet, npm, apt and raw clients, so all of them are fixed.

Where the message reaches the administrator:

  • Preflight (POST /admin/repositories/{name}/imports): preflight_error answers 400 instead of 502, since the error is no longer transient, with the message as its body. crates/server/src/admin/imports.rs itself is unchanged.
  • Worker: a failed listing ends the import at the first read, with the message in last_error; a failed name is a failed item with the message in its detail, and the other names go on (before, an "unreachable" name was retried and then failed the whole import).

Web UI

No UI change is needed: the import screen (web/src/routes/admin/repositories/Import.tsx) shows the preflight's response body, the import's last_error and an item's detail as plain text, so the new messages appear as they are.

Worth knowing

The npm preflight treats an Invalid answer of the search for every package as "no search to walk" and goes on to /-/all. A search page larger than the limit now takes that path as well, rather than ending the preflight with a 502. /-/all then answers, or fails with its own message. A refused target or a redirect loop is caught earlier, by the ping.

Tests

  • Unit tests in import/feed.rs: each of the three errors is Invalid, not transient, and carries the limit and setting, or the URL; a failed transfer is still retried.
  • a_listing_larger_than_forge_reads_fails_at_once_and_says_what_to_do (tests/import.rs): with proxy.max_metadata_bytes = 8192, the preflight answers 400 with the message; an import whose /-/all grew after it was created fails with the message in last_error after one read of /-/all.
  • endless_redirects_and_a_refused_target_fail_at_once_and_name_the_url: the preflight answers 400 for a ping that redirects to itself and for http://169.254.169.254/…; a named package whose packument redirects to itself is a failed item, requested once (6 hits: the request and its 5 redirects), and the other package is imported.

With the old mapping put back, 4 of the 5 unit tests and both integration tests fail (the preflight answers 502 "the source is unreachable"); with the fix they pass.

Checks run locally: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo xtask changelog --check, cargo test -p forge-server --lib import (22 passed), cargo test -p forge-server --test import --test apt_import --test raw_import (27 + 3 + 4 passed). The whole workspace suite and the e2e suite were not run locally.


Generated by Claude Code

…ndless redirects

The import's clients mapped the upstream client's TooLarge, MetadataTarget
and TooManyRedirects to SourceError::Unreachable, which is transient: the
preflight answered 502 "the source is unreachable" and the worker retried
a download that cannot succeed.

They are SourceError::Invalid now: the preflight answers 400 and the worker
fails at once, with a message that says what to change: the limit and
proxy.max_metadata_bytes (for npm's /-/all, also naming the packages or
scopes instead), or the URL.

Fixes #777

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_012e6DJbBFHfotXfRdshLUvS

This branch has not been deployed

No deployments
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.

Imports: an oversized document or a refused target is reported as "unreachable" and retried

2 participants