rate_limit_archlinux

Function rate_limit_archlinux 

Source
pub async fn rate_limit_archlinux() -> OwnedSemaphorePermit
Expand description

What: Apply rate limiting specifically for archlinux.org requests with exponential backoff.

Inputs: None

Output: OwnedSemaphorePermit that the caller MUST hold during the request.

ยงPanics

  • Panics if the archlinux.org request semaphore is closed (should never happen in practice).

Details:

  • Acquires a semaphore permit to serialize archlinux.org requests (only 1 at a time).
  • Uses longer base delay (2 seconds) for archlinux.org to reduce request frequency.
  • Implements exponential backoff: increases delay on consecutive failures (2s โ†’ 4s โ†’ 8s โ†’ 16s, max 60s).
  • Adds random jitter (0-500ms) to prevent thundering herd when multiple clients retry simultaneously.
  • Resets backoff after successful requests.
  • Thread-safe via mutex guarding the rate limiter state.
  • The returned permit MUST be held until the HTTP request completes to ensure serialization.
  • If the permit is dropped before the HTTP request completes, another request may start concurrently, defeating the serialization and potentially causing race conditions or overwhelming the server.