From 028375323f39b2d59bae0abfe20ba187c42bcf16 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 13 Nov 2025 11:43:55 -0500 Subject: [PATCH] cmd/go/internal/modfetch/codehost: fix flaky TestReadZip In normal use by the go command, ReadZip always happens after Stat, which makes sure that the relevant revision has been fetched to local disk. But TestReadZip calls ReadZip directly, and ReadZip was not ensuring that fetch had happened. This made 'go test' pass (because other earlier tests had done Stat of the hg test repo) but 'go test -run=ReadZip' fail by itself. And on big enough machines, the tests that were doing the Stat were running in parallel with ReadZip, causing non-deterministic failures depending on whether the Stat completed before ReadZip started. Fix the race by calling Stat directly in ReadZip, like we already do in ReadFile. Fixes longtest builder flake. Change-Id: Ib42f64876b7ef51d8148c616539b412b42f8b24e Reviewed-on: https://go-review.googlesource.com/c/go/+/720280 Reviewed-by: David Chase Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI --- src/cmd/go/internal/modfetch/codehost/vcs.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/modfetch/codehost/vcs.go b/src/cmd/go/internal/modfetch/codehost/vcs.go index ab04b2e96d..aae1a60bfa 100644 --- a/src/cmd/go/internal/modfetch/codehost/vcs.go +++ b/src/cmd/go/internal/modfetch/codehost/vcs.go @@ -624,15 +624,20 @@ func (r *vcsRepo) ReadZip(ctx context.Context, rev, subdir string, maxSize int64 return nil, vcsErrorf("vcs %s: ReadZip: %w", r.cmd.vcs, errors.ErrUnsupported) } + if rev == "latest" { + rev = r.cmd.latest + } + _, err = r.Stat(ctx, rev) // download rev into local repo + if err != nil { + return nil, err + } + unlock, err := r.mu.Lock() if err != nil { return nil, err } defer unlock() - if rev == "latest" { - rev = r.cmd.latest - } f, err := os.CreateTemp("", "go-readzip-*.zip") if err != nil { return nil, err -- 2.52.0