Safeguard
Developer Tools•

How long do npm, pip and cargo retry a dead registry in CI?

npm, pip and cargo each retry differently when a registry fails. Compare the documented defaults and set job timeouts so CI fails fast and clearly.

Safeguard Security Team
4 min read

It depends on the tool, and the numbers are not comparable. npm retries twice with waits of 10 to 60 seconds and a 5 minute request timeout. pip makes up to 5 connection attempts with a 15 second socket timeout. Cargo retries 3 times. Set a job timeout instead of trusting any of them.

The documented defaults

ToolSettingDefaultWhat it means
npmfetch-retries2Retries idempotent reads on network failures or 5xx errors
npmfetch-retry-mintimeout10 secondsShortest wait between retries
npmfetch-retry-maxtimeout1 minuteLongest wait between retries
npmfetch-retry-factor10Growth factor for the wait
npmfetch-timeout5 minutesLongest wait for one request to finish
pipretries5Maximum attempts to establish a new HTTP connection
piptimeout15 secondsSocket timeout
cargonet.retry3Retries for possibly spurious network errors

These come from the npm config reference, the pip CLI reference and the cargo configuration reference. Defaults can change between versions, so confirm them for the version you run.

Why the numbers mislead

The settings measure different things. pip counts connection attempts, not whole install attempts. npm's retry applies to individual requests, and its request timeout is long enough that one stalled download can hold a job for minutes before a retry even begins. Cargo's value is a count with no wait time stated on the page.

So you cannot add them up into one tidy figure for "how long until CI gives up". A registry that answers slowly instead of failing outright is the worst case, because every request waits for its timeout.

What to do about it

  1. Put a timeout on the whole dependency step, for example 10 minutes. A hung install should fail with a clear message, not sit for an hour. See CI job timeouts stop runaway and hijacked jobs.
  2. Leave the retry counts near their defaults. Raising them in a fleet turns a short outage into a flood of repeat requests, the pattern described in retry storms.
  3. Add one scripted retry around the whole step with a pause, rather than ten tool level retries inside it.
  4. Print which registry host failed. Developers lose time when the log says only "install failed".
  5. Point installs at a mirror you control so the public registry is not in the path. The options are compared in vendoring vs cache vs mirror.

A note on the offline option

npm documents an offline mode that makes no network requests during install and a prefer-offline mode that skips staleness checks for cached data but still fetches what is missing. Cargo documents a net.offline setting that avoids the network and uses locally cached data. These do not replace retries. They are the next step when retries are not enough, covered in npm ci and cache during a registry outage.

Where Safeguard fits

When installs fail and you switch to a cache or mirror, you still need to know which versions went into the build. Safeguard's SBOM and dependency scanning records that inventory per build, so a fallback path does not leave a gap in your records.

Quick check

Should I raise retries to survive outages?

Usually no. Higher counts across many runners add load to a registry that is already struggling. Use a mirror and a job timeout instead.

Are these defaults the same in every version?

Not guaranteed. The values above come from the current documentation we checked. Confirm them against the tool version your runners use.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.