Skip to content

fix(registry): handle HTTP 410/451 for missing crates - #17665

Merged
Muscraft merged 2 commits into
rust-lang:masterfrom
weihanglo:404
Nov 4, 2026
Merged

Muscraft merged 2 commits into
rust-lang:masterfrom
weihanglo:404

Conversation

@weihanglo

Copy link
Copy Markdown
Member

What does this PR try to resolve?

In #16745 we accidentally dropped the handling
for HTTP status code 410 and 451.
While how Cargo handles it is not really documented,
our doc
https://doc.rust-lang.org/nightly/cargo/reference/registry-index.html#nonexistent-crates
does make it sounds like
they are treated the same as 404 non-existent crates.

The regression instead treats those responses are fatal errors,
which affects

  • dependency resolutions,
    which cannot backtrack a old version whose dependency is unavailable,
    like for legal reason we need to take down but it still have
    dependent in the registry.
  • [patch],
    which seeing a non-existent crate should still continue patching.
    This is rare but if some crates take down for some reason with 451,
    users should be able to patch them.
  • cargo add,
    which may stops when queruying a normalized crate name doesn't exist,
    and it won't continue querying the alternative form.

We should restore the old behavior in 1.95 to be a bit resilient.

Resolves #17661

Notes to reviewers

I didn't add tests covering all above.
The two new tests should be sufficient showing that
they went to the same code path.
Can add those if needed.


🤖 LLM involvement: LLM to find if any other stable behavior are affected, and generated two tests

@rustbot rustbot added A-registries Area: registries A-sparse-registry Area: http sparse registries S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 29, 2026
@rustbot

rustbot commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

r? @Muscraft

rustbot has assigned @Muscraft.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @Muscraft, @epage, @weihanglo
  • @Muscraft, @epage, @weihanglo expanded to Muscraft, epage, weihanglo
  • Random selection from Muscraft, epage

@rustbot

This comment has been minimized.

@Turbo87 Turbo87 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rustbot

This comment has been minimized.

@Muscraft Muscraft left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Muscraft
Muscraft added this pull request to the merge queue Nov 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 2, 2026
In rust-lang#16745 we accidentally dropped the handling
for HTTP status code 410 and 451.
While how Cargo handles it is not really documented,
our doc
<https://doc.rust-lang.org/nightly/cargo/reference/registry-index.html#nonexistent-crates>
does make it sounds like
they are treated the same as 404 non-existent crates.

The regression instead treats those responses are fatal errors,
which affects
* dependency resolutions,
  which cannot backtrack a old version whose dependency is unavailable,
  like for legal reason we need to take down but it still have
  dependent in the registry.
* `[patch]`,
  which seeing a non-existent crate should still continue patching.
  This is rare but if some crates take down for some reason with 451,
  users should be able to patch them.
* `cargo add`,
  which may stops when queruying a normalized crate name doesn't exist,
  and it won't continue querying the alternative form.


We should restore the old behavior in 1.95 to be a bit resilient.

I didn't add tests covering all above.
The two new tests should be sufficient showing that
they went to the same code path.
Can add those if needed.

Resolves rust-lang#17661
@rustbot

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Muscraft
Muscraft enabled auto-merge November 4, 2026 02:23
@Muscraft
Muscraft added this pull request to the merge queue Nov 4, 2026
Merged via the queue into rust-lang:master with commit 24de472 Nov 4, 2026
30 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 4, 2026
@weihanglo
weihanglo deleted the 404 branch November 4, 2026 04:35
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 6, 2026
Update cargo submodule

6 commits in 3c747ea3ead23951c1b43a5edfcbdb449135ddeb..111443f3dc4d82a65e2306a93028f122406401c1
2026-11-03 21:25:31 +0000 to 2026-11-05 22:22:33 +0000
- chore: Update libssh2-sys to 0.3.4 (rust-lang/cargo#17692)
- fix(profile): preserve inherited strip  (rust-lang/cargo#17678)
- feat(cargo-platform): implement Serialize/Deserialize for Cfg & CfgExpr (rust-lang/cargo#17598)
- fix: proc-macro typo in &String -&gt; CrateType impl (rust-lang/cargo#17687)
- book faq.md: remove misplaced `)` in offline section (rust-lang/cargo#17682)
- fix(registry): handle HTTP 410/451 for missing crates (rust-lang/cargo#17665)
rust-bors Bot pushed a commit to rust-lang/rust that referenced this pull request Nov 6, 2026
Update cargo submodule

6 commits in 3c747ea3ead23951c1b43a5edfcbdb449135ddeb..111443f3dc4d82a65e2306a93028f122406401c1
2026-11-03 21:25:31 +0000 to 2026-11-05 22:22:33 +0000
- chore: Update libssh2-sys to 0.3.4 (rust-lang/cargo#17692)
- fix(profile): preserve inherited strip  (rust-lang/cargo#17678)
- feat(cargo-platform): implement Serialize/Deserialize for Cfg & CfgExpr (rust-lang/cargo#17598)
- fix: proc-macro typo in &String -&gt; CrateType impl (rust-lang/cargo#17687)
- book faq.md: remove misplaced `)` in offline section (rust-lang/cargo#17682)
- fix(registry): handle HTTP 410/451 for missing crates (rust-lang/cargo#17665)
@rustbot rustbot added this to the 1.101.0 milestone Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-registries Area: registries A-sparse-registry Area: http sparse registries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sparse registries returning 410 or 451 for index files cause an error instead of "not found"

4 participants