uv: Add support for retrying connection failures

Tested with uv 0.1.41

While looking for workarounds to https://github.com/astral-sh/uv/issues/3512, I experimented with using --no-cache. In our case, this actually increased the failure rate, as we use a local artifactory based pypi mirror which appears rate limited. Using the same bash script as in the linked issue but with --no-cache added, and with significantly more packages, we began observing instances where the artifactory server would be overwhelmed and UV would fail with connection reset by peer.

Under pip, this was also reproducible though it required a larger number of simultaneous processes (~80), but rather that failing outright PIP would retry connection failures. Please add (ideally configurable) support for retrying connection failures when downloading or querying indexes

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 50 (32 by maintainers)

Commits related to this issue

Most upvoted comments

Happy to report uv v0.2.26 runs smoothly for me, no more failures when downloading wheels.

I think the issue is with stream_wheel, if I change https://github.com/astral-sh/uv/blob/9a44bc1d3567e0a2ba31675bc35c50392fc2f5ad/crates/uv-distribution/src/distribution_database.rs#L211 to remove the if to unconditional try download_wheel when stream_wheel fails with Extract error, uv correctly retries.

error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: beautifulsoup4==4.12.3
  Caused by: Request failed after 3 retries
  Caused by: error sending request for url (https://files.pythonhosted.org/packages/b1/fe/e8c672695b37eecc5cbf43e1d0638d88d66ba3a44c4d321c796f4e59167f/beautifulsoup4-4.12.3-py3-none-any.whl)
  Caused by: client error (Connect)
  Caused by: tcp connect error: Connection refused (os error 111)
  Caused by: Connection refused (os error 111)

so my guess is that reqwest-retry does not support retrying streaming response? Can we have a config/option/env var to force download_wheel?

All the errors were related to running uv pip compile, so it was only trying to collect metadata? I don’t have any additional output than what I posted.

The index is https://pypi.org/, but the network involves a Palo Alto firewall that will be decrypting and encrypting traffic, and it seems occasionally this will just fail (either kill the connection or send an empty body).

I’ve seen a regression in this recently, in the last few days, using the latest version of uv, I’ve started seeing:

⠼ defusedxml==0.7.1                                                                                                                                                                                                                                          error: Failed to download `defusedxml==0.7.1`
  Caused by: request or response body error
  Caused by: error reading a body from connection
  Caused by: Connection reset by peer (os error 104)

I run again and it’s fine, but I thought uv was now retrying these low level network errors?

It could of course just be my corporate network environment getting worse, worth reporting a new issue?

@charliermarsh These failures happened with uv 0.2.29 (you can check the link to our GitHub Actions to see some non-verbose logs). I’m pretty sure I’ve seen it on earlier versions as well.

Haven’t seen it yet with 0.2.30, but I can post here if I do see it. But I don’t believe 0.2.30 contains any fixes related to this issue.

If it helps, I can set our CI to verbose to get better logs on this issue?

I’m unable to reproduce in my end either, curious if this resolves other’s issues as well.

Maybe because the unzip error causing an early error return?

Found this, will try with that env var

I’ll take this build for a spin on my testing farm. The networking issues I was suffering were infrequent so I won’t be able to say for certain but if it shows up I’ll let you know

I put up a patch at #4960 if anyone wants to give it a try.

Judging from the code, reqwest-retry simply won’t retry body errors.

I’m using uv 0.2.23, the error message is

error: Failed to prepare distributions
  Caused by: Failed to fetch wheel: jaxlib==0.4.16+cuda12.cudnn89
  Caused by: Failed to extract archive
  Caused by: error decoding response body
  Caused by: request or response body error
  Caused by: error reading a body from connection
  Caused by: Connection reset by peer (os error 104)

Hi @aybidi — we think this is important to address but haven’t started working on a fix yet. If anyone is willing to investigate and contribute in the meantime I’m happy to review.

I assume those retries don’t apply to streaming operations. Like, they apply to the initial request itself, but probably not the entirety of reading from the stream? We can fix this by adding our own retry around download operations.

Looking at it again, it does seem like it would retry on resets, see retryable_strategy.rs#L192