Skip to content

feat(network): use Retry-After header for HTTP 429 responses #15463

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arlosi
Copy link
Contributor

@arlosi arlosi commented Apr 29, 2025

What does this PR try to resolve?

Cargo registries that return HTTP 429 when the service is overloaded expect the client to retry the request automatically after a delay. Cargo currently does not retry for HTTP 429.

What changed?

  • Adds HTTP 429 (too many requests) as a spurious HTTP error to enable retries.
  • Parse the Retry-After HTTP header to determine how long to wait before a retry.

In this implementation, the maximum delay is limited to Cargo's existing limit of 10 seconds. We could consider increasing that limit for this case, since the server is explicitly requesting the delay.

@rustbot
Copy link
Collaborator

rustbot commented Apr 29, 2025

r? @ehuss

rustbot has assigned @ehuss.
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

@rustbot rustbot added A-networking Area: networking issues, curl, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 29, 2025
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

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

cc #13530, which I believe this partially resolves it.

@@ -47,6 +47,7 @@ use anyhow::Error;
use rand::Rng;
use std::cmp::min;
use std::time::Duration;
use time::OffsetDateTime;
Copy link
Member

Choose a reason for hiding this comment

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

I feel like we are on the way of dropping time? #15293

@arlosi
Copy link
Contributor Author

arlosi commented Apr 29, 2025

cc #13530, which I believe this partially resolves it.

This only applies for things that use Retry. IIRC the publishing logic doesn't have built-in retries at all.

@ehuss
Copy link
Contributor

ehuss commented Apr 29, 2025

Would it be possible to add a test using our HttpServer to ensure that this works going through curl? I imagine it would be something like adding a custom_responders?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-networking Area: networking issues, curl, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants