go: cmd/go: retry failed fetches

$ go version
go version go1.11.1 darwin/amd64
package main

import (
	_ "github.com/google/go-cloud/wire/cmd/wire"
)

func main() {
	//
}
go build -o a.out
go: finding github.com/google/go-cloud/wire/cmd/wire latest
go: finding github.com/google/go-cloud/wire/cmd latest
go: finding github.com/google/go-cloud/wire latest
go: finding google.golang.org/api v0.0.0-20180606215403-8e9de5a6de6d
go: google.golang.org/api@v0.0.0-20180606215403-8e9de5a6de6d: git fetch -f https://code.googlesource.com/google-api-go-client refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /Users/chai/go/pkg/mod/cache/vcs/9e62a95b0409d58bc0130bae299bdffbc7b7e74f3abe1ecf897474cc474b8bc0: exit status 128:
        error: RPC failed; curl 18 transfer closed with outstanding read data remaining
        fatal: The remote end hung up unexpectedly
        fatal: early EOF
        fatal: index-pack failed
go: error loading module requirements

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 16
  • Comments: 22 (10 by maintainers)

Commits related to this issue

Most upvoted comments

go: finding github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72
go: golang.org/x/tools@v0.0.0-20190729092621-ff9f1409240a: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/b44680b3c3708a854d4c89f55aedda0b223beb8d9e30fba969cefb5bd9c1e843: exit status 128:
	fatal: the remote end hung up unexpectedly
	fatal: early EOF
	fatal: index-pack failed
go: golang.org/x/tools@v0.0.0-20190311212946-11955173bddd: unknown revision 11955173bddd
go: golang.org/x/tools@v0.0.0-20180221164845-07fd8470d635: unknown revision 07fd8470d635
go: golang.org/x/tools@v0.0.0-20190114222345-bf090417da8b: unknown revision bf090417da8b
go: golang.org/x/text@v0.3.0: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /go/pkg/mod/cache/vcs/5b03666c2d7b526129bad48c5cea095aad8b83badc1daa202e7b0279e3a5d861: exit status 128:
	fatal: the remote end hung up unexpectedly
	fatal: early EOF
	fatal: index-pack failed
go: error loading module requirements

for me it was a kind of same problem; using GOPROXY=https://proxy.golang.org fixed it

@thempatel Thanks for the idea.

I created this script that uses as a base go mod download to download the dependency and if it fails try again.

The script tries to download the dependency 5 times with an interval of 20 seconds.

#!/bin/bash
go mod download $@;
status=$?;
attempt=1;
while [ $status -ne 0 ] && [ $attempt -le 5 ]; do
    sleep 20;
    (( attempt++ ));
    go mod download $@;
    status=$?;
done;

@eduardo-mior similar to @linzhp we at FullStory also use a module cache directory that we pre-populate in our CI jobs. You can build a retry loop in your flavor of shell (e.g. https://unix.stackexchange.com/a/82610) and wrap go mod download inside of it. For us, the process of archiving and inflating all of our dependencies is slower than simply re-downloading them all so we prefer that route but could be a good avenue for you.

@mvdan Is there any solutions, such as copy the git repository directly to the mod directory? I always get this problem,under $GOPATH I can download the zip file from git then do some other work to solve it, but with go mod I have no idea. Thanks~