Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: git fetch errors dropped when producing pseudo-versions for commits #53935

Closed
bcmills opened this issue Jul 18, 2022 · 9 comments
Closed
Assignees
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Jul 18, 2022

--- FAIL: TestScript (0.01s)
    --- FAIL: TestScript/mod_get_direct (158.26s)
        script_test.go:270: 
            # (2022-07-14T21:40:47Z)
            # Regression test for golang.org/issue/34092: with an empty module cache,
            # 'GOPROXY=direct go get golang.org/x/tools/gopls@master' did not correctly
            # resolve the pseudo-version for its dependency on golang.org/x/tools. (158.242s)
            > [short] skip
            > [!net] skip
            > [!exec:git] skip
            > env GO111MODULE=on
            > env GOPROXY=direct
            > env GOSUMDB=off
            > go list -m cloud.google.com/go@main
            [stdout]
            cloud.google.com/go v0.0.0-20220714214024-fc3417be70cd
            > ! stdout 'v0.0.0-'
            FAIL: testdata/script/mod_get_direct.txt:14: unexpected match for `(?m)v0.0.0-` found in stdout: v0.0.0-
            
FAIL
FAIL	cmd/go	262.233s

greplogs -l -e 'FAIL: TestScript/mod_get_direct .*(?:\n .*)*found in stdout: v0.0.0-'
2022-07-14T21:16:23-dc00aed/linux-amd64-longtest
2022-05-19T15:38:08-e23cc08/linux-386-longtest
2022-05-18T15:25:04-1f9f7db/linux-386-longtest

@bcmills bcmills added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. modules labels Jul 18, 2022
@bcmills bcmills added this to the Backlog milestone Jul 18, 2022
@bcmills
Copy link
Contributor Author

bcmills commented Jul 18, 2022

This is probably a symptom of a missing error-check somewhere, combined with an intermittent flake connecting to cloud.google.com or its VCS host (compare #51051).

Independent of the flaky cloud.google.com dependency, we should find and fix the missing error check.

@bcmills
Copy link
Contributor Author

bcmills commented Aug 22, 2022

A mod_invalid_version failure with a similar pathology:
2022-08-18T19:12:13-0eb56ca/linux-386-longtest

            > go mod edit -require github.com/pierrec/lz4@473cd7ce01a1
            > go list -m github.com/pierrec/lz4
            [stdout]
            github.com/pierrec/lz4 v0.0.0-20190131084431-473cd7ce01a1
            > stdout 'github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1'
            FAIL: testdata/script/mod_invalid_version.txt:186: no match for `(?m)github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1` found in stdout

@bcmills bcmills changed the title cmd/go: TestScript/mod_get_direct failures with v0.0.0- pseudo-versions cmd/go: git test failures with v0.0.0- pseudo-versions Aug 22, 2022
@gopherbot
Copy link

Change https://go.dev/cl/426079 mentions this issue: cmd/go/internal/modfetch: report error on failing to derive pseudo version from recent tag

@ZekeLu
Copy link
Contributor

ZekeLu commented Aug 27, 2022

I have managed to reproduce the issue with this script:

#!/bin/bash
for i in {1..10000}; do
    echo "$(date +%T): try $i times"
    echo "$(date +%T): try $i times ======" >> log.txt
    go clean -modcache && GOPROXY=direct GOSUMDB=off gotip list -x -m github.com/pierrec/lz4@473cd7ce01a1 >>log.txt 2>&1

    if tail -n 2 log.txt | grep -F v0.0.0; then
        echo "$(date +%T): reproduced"
        exit 0
    fi
done

The script is executed in the directory with the following files:

-- go.mod --
module example.com

go 1.14
-- go.sum --

Notes:

  • I can not access cloud.google.com so I tested against github.com/pierrec/lz4@473cd7ce01a1 instead.
  • the network between my computer and github.com is bad (which makes it easy to reproduce the issue 😄 )
diff between a succeeded log and a failed log

Note: The duration before # cd is modified manually to reduce the noice.

--- succeeded.log	2022-08-27 10:48:19.000000000 +0800
+++ failed.log	2022-08-27 02:15:11.406606020 +0800
@@ -1,46 +1,40 @@
 mkdir -p /home/zeke/go/pkg/mod/cache/vcs # git3 https://github.com/pierrec/lz4
 # lock /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7.lock
 mkdir -p /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7 # git3 https://github.com/pierrec/lz4
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git init --bare
 0.001s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git init --bare
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git remote add origin -- https://github.com/pierrec/lz4
 0.001s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git remote add origin -- https://github.com/pierrec/lz4
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 473cd7ce01a1 --
 0.001s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 473cd7ce01a1 --
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git ls-remote -q origin
 34.014s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git ls-remote -q origin
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git tag -l
 0.003s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git tag -l
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f --depth=1 origin refs/tags/v2.0.8:refs/tags/v2.0.8
 129.970s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f --depth=1 origin refs/tags/v2.0.8:refs/tags/v2.0.8
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' refs/tags/v2.0.8 --
 0.003s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' refs/tags/v2.0.8 --
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 08c27939df1bd95e881e2c2367a749964ad1fceb --
 0.002s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 08c27939df1bd95e881e2c2367a749964ad1fceb --
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f --depth=1 origin refs/tags/v1.0.1:refs/tags/v1.0.1
 120.220s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f --depth=1 origin refs/tags/v1.0.1:refs/tags/v1.0.1
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f origin 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
 239.611s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f origin 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch --unshallow -f origin
 121.158s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch --unshallow -f origin
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 473cd7ce01a1113208073166464b98819526150e --
 0.005s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 473cd7ce01a1113208073166464b98819526150e --
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
 0.003s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git for-each-ref --format %(refname) refs/tags --merged 473cd7ce01a1113208073166464b98819526150e
 0.007s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git for-each-ref --format %(refname) refs/tags --merged 473cd7ce01a1113208073166464b98819526150e
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f origin 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
-0.922s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f origin 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
+151.841s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch -f origin 'refs/heads/*:refs/heads/*' 'refs/tags/*:refs/tags/*'
-cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch --unshallow -f origin
-4.288s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git fetch --unshallow -f origin
-cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git for-each-ref --format %(refname) refs/tags --merged 473cd7ce01a1113208073166464b98819526150e
-0.007s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git for-each-ref --format %(refname) refs/tags --merged 473cd7ce01a1113208073166464b98819526150e
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
 0.003s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
-cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git merge-base --is-ancestor -- v1.0.1 473cd7ce01a1113208073166464b98819526150e
-0.003s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git merge-base --is-ancestor -- v1.0.1 473cd7ce01a1113208073166464b98819526150e
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
 0.002s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
 cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
 0.001s # cd /home/zeke/go/pkg/mod/cache/vcs/036595127a116abca3f2bfd7bedafedb33d890c2b102d96361815966679432e7; git cat-file blob 473cd7ce01a1113208073166464b98819526150e:go.mod
-github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1
+github.com/pierrec/lz4 v0.0.0-20190131084431-473cd7ce01a1

From the log I found that git fetch --unshallow -f origin is not executed when it failed. Which could happen on line 558 below:

func (r *gitRepo) fetchRefsLocked() error {
if r.fetchLevel < fetchAll {
// NOTE: To work around a bug affecting Git clients up to at least 2.23.0
// (2019-08-16), we must first expand the set of local refs, and only then
// unshallow the repository as a separate fetch operation. (See
// golang.org/issue/34266 and
// https://github.com/git/git/blob/4c86140027f4a0d2caaa3ab4bd8bfc5ce3c11c8a/transport.c#L1303-L1309.)
if _, err := Run(r.dir, "git", "fetch", "-f", r.remote, "refs/heads/*:refs/heads/*", "refs/tags/*:refs/tags/*"); err != nil {
return err
}
if _, err := os.Stat(filepath.Join(r.dir, "shallow")); err == nil {
if _, err := Run(r.dir, "git", "fetch", "--unshallow", "-f", r.remote); err != nil {
return err
}
}
r.fetchLevel = fetchAll
}
return nil
}

And finally I found that the error is ignored on line 610 below:

if pseudoBase == "" {
tag, _ := r.code.RecentTag(info.Name, tagPrefix, tagAllowed)
if tag != "" {
pseudoBase, _ = tagToVersion(tag)
}
}

I can reproduce the issue by modifying src/cmd/go/internal/modfetch/codehost/git.go like this:

diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go
index ac2dc2348e..921f7d32cf 100644
--- a/src/cmd/go/internal/modfetch/codehost/git.go
+++ b/src/cmd/go/internal/modfetch/codehost/git.go
@@ -554,9 +554,7 @@ func (r *gitRepo) fetchRefsLocked() error {
        // golang.org/issue/34266 and
        // https://github.com/git/git/blob/4c86140027f4a0d2caaa3ab4bd8bfc5ce3c11c8a/transport.c#L1303-L1309.)
 
-       if _, err := Run(r.dir, "git", "fetch", "-f", r.remote, "refs/heads/*:refs/heads/*", "refs/tags/*:refs/tags/*"); err != nil {
-           return err
-       }
+       return fmt.Errorf("Hardcoded error")
 
        if _, err := os.Stat(filepath.Join(r.dir, "shallow")); err == nil {
            if _, err := Run(r.dir, "git", "fetch", "--unshallow", "-f", r.remote); err != nil {

https://go.dev/cl/426079 has been sent to fix this issue.

@bcmills
Copy link
Contributor Author

bcmills commented Aug 29, 2022

@gopherbot, please backport to Go 1.18 and 1.19. This can cause the go command to resolve unexpected pseudo-versions for commits and branches, and the fix is very small.

@gopherbot
Copy link

Backport issue(s) opened: #54733 (for 1.18), #54734 (for 1.19).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@bcmills bcmills changed the title cmd/go: git test failures with v0.0.0- pseudo-versions cmd/go: git fetch errors dropped when producing pseudo-versions for commits Aug 29, 2022
@gopherbot
Copy link

Change https://go.dev/cl/426494 mentions this issue: [release-branch.go1.19] cmd/go/internal/modfetch: report error on failing to derive pseudo version from recent tag

@gopherbot
Copy link

Change https://go.dev/cl/426514 mentions this issue: [release-branch.go1.18] cmd/go/internal/modfetch: report error on failing to derive pseudo version from recent tag

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 29, 2022
@gopherbot
Copy link

Change https://go.dev/cl/426495 mentions this issue: cmd/go/internal/modfetch: distinguish "unsupported" errors from RecentTag

gopherbot pushed a commit that referenced this issue Aug 29, 2022
…tTag

CL 426079 started checking errors from RecentTag.
Unfortunately, we forgot to run "-longtest" SlowBots, and it turns out
to have broken non-short tests for non-git VCS implementations,
because those don't implement the RecentTag method.

Updates #53935.

Change-Id: I5935f2f4b3f684515e99e8bf70a840154c36249f
Reviewed-on: https://go-review.googlesource.com/c/go/+/426495
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Aug 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants