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

proposal: cmd/go: fallback to module cache, if proxy is not reachable #43646

Merovius opened this issue Jan 12, 2021 · 2 comments

proposal: cmd/go: fallback to module cache, if proxy is not reachable #43646

Merovius opened this issue Jan 12, 2021 · 2 comments


Copy link

@Merovius Merovius commented Jan 12, 2021

When I try to import a yet-unrequired module, e.g.

mero@hix ~/src/$ cat foo.go 
package main

import ""

func main() {
	var _ qr.Code
mero@hix ~/src/$ cat go.mod

go 1.15

and I run go mod tidy, while not connected to the internet, I get an error

go: finding module for package imports module Get "": dial tcp: lookup on [::1]:53: read udp [::1]:57927->[::1]:53: read: connection refused

That makes sense - the proxy is not reachable. However, my module cache contains a usable version of this module:

mero@hix ~/src/$ l -d ~/pkg/mod/ 
dr-x------. 5 mero mero 4,0K 14. Mai 2020  /home/mero/pkg/mod/

So, it might be a reasonable course of action for me, to just use the version I have in the cache - whether it is the latest, or not. If I want to do that, as far as I can tell, either

a) I have to look up what versions I have in my cache and run go get, to update go.mod. It would be great, if that could be automated, or
b) set GOPROXY=file:///home/mero/pkg/mod/cache/download and run go mod tidy

Both of these can be considered somewhat clunky (and the latter is not very discoverable). I would like to suggest to make this easier. There are several ways this could happen:

  1. Automatically fall back to the module cache when running go mod tidy or similar and a network error happens. IMO that would be the most convenient - it also has the downside of unexpectedly adding an outdated version of the module.
  2. Add a value to the -mod flag that is equivalent to -mod=mod, but only touching the local cache.
  3. Add a flag to go mod tidy (and similar), to use the local cache as a proxy (essentially automate setting the environment variable).

It's also fine, if this is deemed WAI, of course. I just thought I would suggest it after the case came up on golang-nuts.

@gopherbot gopherbot added this to the Proposal milestone Jan 12, 2021
@gopherbot gopherbot added the Proposal label Jan 12, 2021
Copy link

@jayconrod jayconrod commented Jan 12, 2021

cc @bcmills @matloob @rsc

Closely related: #32337

We've also talked about adding GOPROXY=cache, which would be similar to GOPROXY=file://$(go env GOMODCACHE)/cache/download, but would synthesize version lists and .info files.

Copy link

@Merovius Merovius commented Jan 12, 2021

GOPROXY=cache would also address this and is, I think, a very logical place for that knob (and far easier to remember than the path).

@ianlancetaylor ianlancetaylor changed the title Proposal: cmd/go: Fallback to module cache, if proxy is not reachable proposal: cmd/go: fallback to module cache, if proxy is not reachable Jan 12, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.