Skip to content

zig package manager should retry fetching on temporary errors #17472

Open

Description

@mitchellh

Zig Version

0.12.0-dev.790+ad6f8e3a5

Steps to Reproduce and Observed Behavior

My project (Ghostty) has ~20 dependencies it has to fetch from the internet given an uncached build. These are fetched from multiple sources (github, gitlab, self-hosted, etc.). Each push results in ~7 separate CI runs which run uncached. As a result, each Git push results in ~140 new HTTP fetches for these large files.

Even with this relatively small number, its big enough that I'm regularly seeing temporary errors fail CI. These are the sorts of errors that an immediate retry fixes the issue 90% of the time, and a very short backoff fixes the issue the remaining 10% of the time. So far, none of the failures have been real persisted outages.

Expected Behavior

Zig should retry on fetch errors.

The ones I've seen but this likely isn't exhaustive:

  • error.TemporaryNameServerFailure temporary is even in the name!
  • HTTP 500 errors, namely 502 which is usually a single backend down while others are still up
  • HTTP 400 errors even, I've received a 404 before when the package existed, likely a CDN issue where some edges have it and others don't

My recommendation would be to do a short series of backoffs. Even backing off a few times with a maximum total wait time of 10 seconds would probably fix 90% of my issues, but perhaps this can be configurable because for CI I'd happily configure this to upwards of a few minutes.

The backoff should probably increase, whether it be exponential, fibbonacci, whatever.

As a workaround, I can make my whole CI job retry, but the CI job does a lot of other setup and no other steps in the job are flaky so this would probably result in retrying genuine failures and cost me more money. It'd be much more convenient and faster if Zig retried.

Activity

  1. added
    bug
    on Oct 10, 2023
  2. added
    zig build system
    on Oct 10, 2023
  3. added this to the 0.12.0 milestone on Oct 10, 2023
  4. added
    enhancement
    and removed
    bug
    on Oct 10, 2023
  5. modified the milestones: 0.12.0, 0.13.0 on Feb 14, 2024
  6. modified the milestones: 0.14.0, 0.15.0 on Oct 1, 2024
  7. andrewrk commented on Oct 1, 2024

    @andrewrk
    Member

    Still interested in solving this issue, but wanted to suggest an alternative workaround for the time being. Could you try persisting your p directory in the global zig cache across CI invocations? Or maybe even your entire global zig cache directory since you're using the same zig version.

    I think it's a nice workaround because it's something valuable to do regardless - will make your CI run faster and use less network resources. For example, mlugg's Setup Zig Action does this by default.

  8. mitchellh commented on Oct 1, 2024

    @mitchellh
    ContributorAuthor

    Still interested in solving this issue, but wanted to suggest an alternative workaround for the time being. Could you try persisting your p directory in the global zig cache across CI invocations? Or maybe even your entire global zig cache directory since you're using the same zig version.

    We are doing this now! This plus I've mirrored all my dependency in a single web host I use has made this a non-issue for me. I think generally its still useful to solve but I have successfully worked around it.

  9. mitchellh commented on Oct 26, 2025

    @mitchellh
    ContributorAuthor

    As an update here, note that the "mirror your dependencies" workaround helped a lot, but I can only do that for direct dependencies. The major issue now as more Zig projects have adopted the build system and we've adopted more Zig deps are transitive dependencies.

    Retries would help a lot here.

    There is another issue I know tracking mirroring transitives. That'd be even better.

  10. andrewrk commented on Oct 26, 2025

    @andrewrk
    Member

    That reminds me - one thing I noticed when reworking the DNS lookup code for #25592 is that DNS queries were never retried ever which is kind of a basic failure of using the UDP protocol. The "TemporaryNameServerFailure" error isn't even possible anymore in the reworked Linux code because it now retries properly (an amount configurable in /etc/resolv.conf).

    I don't think that closes this issue entirely, but it does make me curious, did the problem happen on macOS or Windows, which use getaddrinfo from libc?

  11. mitchellh commented on Oct 26, 2025

    @mitchellh
    ContributorAuthor

    I don't think that closes this issue entirely, but it does make me curious, did the problem happen on macOS or Windows, which use getaddrinfo from libc?

    I only noticed in CI, which is primarily Linux. We do run macOS as well and I don't recall those machines failing but memory is fallible...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementzig build system

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions