internal/worker: on fetch, hit proxy info first

Ask the proxy for info on the requested module version before doing
anything else, even computing the latest versions. This will make the
proxy aware of the version if it isn't already.

This prevents the failure mode described in the linked issue: the user
does frontend fetch on a new, latest version before the proxy sees it,
so the latest-version info doesn't know about it.

For golang/go#46985

Change-Id: I681da5404cea2d391836d876ac807b714ce88f90
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/340123
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
diff --git a/internal/worker/fetch.go b/internal/worker/fetch.go
index 15e8ef4..428e3aa 100644
--- a/internal/worker/fetch.go
+++ b/internal/worker/fetch.go
@@ -66,6 +66,12 @@
 		trace.StringAttribute("version", requestedVersion))
 	defer span.End()
 
+	// Begin by htting the proxy's info endpoint. That will make the proxy aware
+	// of the version if it isn't already, as can happen when we arrive here via
+	// frontend fetch. We ignore both the error and the information itself at
+	// this point; we will ask again later when we need it.
+	_, _ = f.ProxyClient.Info(ctx, modulePath, requestedVersion)
+
 	// Get the latest-version information first, and update the DB. We'll need
 	// it to determine if the current module version is the latest good one for
 	// its path.
@@ -411,6 +417,7 @@
 // it must be protected by the module-path advisory lock.
 func (f *Fetcher) FetchAndUpdateLatest(ctx context.Context, modulePath string) (_ *internal.LatestModuleVersions, err error) {
 	defer derrors.Wrap(&err, "FetchAndUpdateLatest(%q)", modulePath)
+
 	lmv, err := fetch.LatestModuleVersions(ctx, modulePath, f.ProxyClient, func(v string) (bool, error) {
 		return f.DB.HasGoMod(ctx, modulePath, v)
 	})