Skip to content

gomod: retry module downloads that fail mid-stream - #71

Merged
sipsma merged 1 commit into
dagger:mainfrom
sipsma:goproxy-retry-mid-stream
Oct 21, 2026
Merged

sipsma merged 1 commit into
dagger:mainfrom
sipsma:goproxy-retry-mid-stream

Conversation

@sipsma

@sipsma sipsma commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

What fails. proxy.golang.org sometimes resets a module zip download partway through: read "https://proxy.golang.org/<module>/@v/<version>.zip": stream error: stream ID N; INTERNAL_ERROR; received from peer. In dagger/dagger's CI this shows up repeatedly (12 confirmed incidents plus 5 candidates on Oct 19-20), including in golang/generate-all and golang/test-all, which use this module.

Why it fails.

  • Without an explicit GOPROXY, Go uses https://proxy.golang.org,direct. In cmd/go, a zip body-read error happens inside TryProxies (src/cmd/go/internal/modfetch/fetch.go:304-325, proxy.go:418-440).
  • After a ,, only a 404 or 410 moves on to the next entry; after a |, any error does (proxy.go:50-58, 179). So a reset fails the build.

The change.

  • withGoCaches, which every Go container in this repo goes through (the default toolchain container, a caller's baseImage, per-directory containers, golangci-lint, staticcheck), now sets GOPROXY=https://proxy.golang.org|https://proxy.golang.org|direct unless the container already has a non-empty GOPROXY.
  • The in-process scanner container, which mounts the caches itself, gets the same value.
  • A zip download that fails mid-stream now retries the proxy once (a new request), then tries the origin. The Alpine-based images here have no git, so an origin fetch of a VCS-hosted module may also fail there; the proxy retry is the main benefit.
  • proxyList doesn't deduplicate entries, so repeating the proxy is a supported way to get one retry.
  • The existing go.sum/GOSUMDB verification policy is unchanged.

Evidence (through Dagger, on a dedicated engine):

Check Result
gomod | with-go-caches <golang:1.26-alpine> | with-exec go env GOPROXY https://proxy.golang.org|https://proxy.golang.org|direct
The same, with a base that sets GOPROXY=https://private.example.invalid|off keeps https://private.example.invalid|off
The repo's full dagger check 51 passed

The same | mechanism was demonstrated with a fault-injecting proxy in dagger/dagger #14750: , fails with read "…zip": unexpected EOF, while the repeated-proxy form retries and succeeds.

Cost and limits.

  • Lookup errors propagate: withGoCaches now reads the caller container's GOPROXY, which resolves that container's metadata. If that lookup fails, the error propagates (the call fails) rather than being ignored.
  • Zip only: the repeat retries zip downloads, not .info/.mod lookups, whose errors are cached per proxy and module.
  • Origin fallback: direct adds VCS, network, auth and rate-limit exposure where it applies.
  • Cache keys: affected execs are invalidated once; the shared go-mod/go-build cache volumes stay reusable.

Reaching dagger/dagger.

  • dagger/dagger's dagger.toml has [modules.golang] source = "dagger.io/go@pull/45/head". Select generation by directory #45 is merged and its head is frozen at a Sep 15 commit (also the dagger.lock pin), so this change has no effect there by itself.
  • To use it, dagger/dagger needs a new source ref (a new tag, @main or a SHA) plus a lock refresh.
  • Moving off pull/45/head also adopts every dagger/go change since Sep 15, not just this one.

@grouville
grouville self-requested a review October 21, 2026 19:03
proxy.golang.org sometimes resets a module zip download partway through
("read ... .zip: stream error: stream ID N; INTERNAL_ERROR; received from
peer"). With Go's default GOPROXY ("https://proxy.golang.org,direct")
only a 404 or 410 falls through to the next entry, so the build fails.

Set GOPROXY to "https://proxy.golang.org|https://proxy.golang.org|direct"
in withGoCaches, which every Go container here goes through, and in the
in-process scanner container. "|" falls through on any error, so a zip
download that fails mid-stream retries the proxy once and then fetches
from the origin. A container that sets a non-empty GOPROXY keeps it. The
existing go.sum and GOSUMDB verification policy is unchanged.

Signed-off-by: Erik Sipsma <[email protected]>
@sipsma
sipsma force-pushed the goproxy-retry-mid-stream branch 2 times, most recently from be35181 to 0e3a601 Compare October 21, 2026 19:06
@sipsma
sipsma merged commit f1536f0 into dagger:main Oct 21, 2026
52 checks passed
sipsma added a commit to sipsma/dagger that referenced this pull request Oct 21, 2026
…retries

The golang workspace module (generate and test checks) still used
dagger/go's pull/45 head, which is frozen at its September merge. Pin it
to the dagger/go main merge of dagger/go#71, which also contains
dagger/go#72:

- dagger/go#71 sets GOPROXY to proxy.golang.org|proxy.golang.org|direct
  in withGoCaches, so a module zip download that the proxy resets
  mid-stream is retried once against the proxy and, on another proxy
  failure, attempted directly from the origin. The check can still fail
  if that fallback fails.
- dagger/go#72 speeds up package discovery.

The source names a commit rather than main because dagger.lock pins are
not applied in Cloud's remote-workspace sessions, so main would float in
CI. The dagger/go main entry in dagger.lock is refreshed to the same
commit with dagger lock update.

dagger/go now organizes checks and generators by package, so their names
change: golang/generate-all/stale becomes golang/packages/generate/stale,
golang/test-all becomes golang/packages/tests/test, and the
golang/generate-all generator becomes golang/packages/generate. Update
the release instructions' generate step to the new generator name.

Signed-off-by: Erik Sipsma <[email protected]>
sipsma added a commit to sipsma/dagger that referenced this pull request Oct 21, 2026
…retries

The golang workspace module (generate and test checks) still used
dagger/go's pull/45 head, which is frozen at its September merge. Pin it
to the dagger/go main merge of dagger/go#73, which also contains
dagger/go#71 and dagger/go#72:

- dagger/go#71 sets GOPROXY to proxy.golang.org|proxy.golang.org|direct
  in withGoCaches, so a module zip download that the proxy resets
  mid-stream is retried once against the proxy and, on another proxy
  failure, attempted directly from the origin. The check can still fail
  if that fallback fails.
- dagger/go#72 and dagger/go#73 speed up and fix package discovery.

The source names a commit rather than main because dagger.lock pins are
not applied in Cloud's remote-workspace sessions, so main would float in
CI. The dagger/go main entry in dagger.lock is refreshed to the same
commit with dagger lock update.

dagger/go now organizes checks and generators by package, so their names
change: golang/generate-all/stale becomes golang/packages/generate/stale,
golang/test-all becomes golang/packages/tests/test, and the
golang/generate-all generator becomes golang/packages/generate. Update
the release instructions' generate step to the new generator name.

Signed-off-by: Erik Sipsma <[email protected]>
sipsma added a commit to sipsma/dagger that referenced this pull request Oct 21, 2026
…retries

The golang workspace module (generate and test checks) still used
dagger/go's pull/45 head, which is frozen at its September merge. Pin it
to the dagger/go main merge of dagger/go#73, which also contains
dagger/go#71 and dagger/go#72:

- dagger/go#71 sets GOPROXY to proxy.golang.org|proxy.golang.org|direct
  in withGoCaches, so a module zip download that the proxy resets
  mid-stream is retried once against the proxy and, on another proxy
  failure, attempted directly from the origin. The check can still fail
  if that fallback fails.
- dagger/go#72 and dagger/go#73 speed up and fix package discovery.

The source names a commit rather than main because dagger.lock pins are
not applied in Cloud's remote-workspace sessions, so main would float in
CI. The dagger/go main entry in dagger.lock is refreshed to the same
commit with dagger lock update.

dagger/go now organizes checks and generators by package, so their names
change: golang/generate-all/stale becomes golang/packages/generate/stale,
golang/test-all becomes golang/packages/tests/test, and the
golang/generate-all generator becomes golang/packages/generate. Update
the release instructions' generate step to the new generator name.

Signed-off-by: Erik Sipsma <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants