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,cmd/doc: http activity during 'go doc' #47196

rsc opened this issue Jul 14, 2021 · 2 comments

cmd/go,cmd/doc: http activity during 'go doc' #47196

rsc opened this issue Jul 14, 2021 · 2 comments
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.


Copy link

rsc commented Jul 14, 2021

I made this change to my repo and did go install cmd/go.

diff --git a/src/net/http/client.go b/src/net/http/client.go
index e0cabc9d4c..9973cdcb23 100644
--- a/src/net/http/client.go
+++ b/src/net/http/client.go
@@ -590,6 +590,7 @@ func urlErrorOp(method string) string {
 // Any returned error will be of type *url.Error. The url.Error
 // value's Timeout method will report true if the request timed out.
 func (c *Client) Do(req *Request) (*Response, error) {
+	panic("HTTP")

Then I did cd $GOPATH/src/; go doc, and I get:

% go doc
panic: HTTP

goroutine 1 [running]:
	/Users/rsc/go/src/cmd/go/internal/web/http.go:112 +0x132
cmd/go/internal/web.get(0x1, 0xc0001c6480)
	/Users/rsc/go/src/cmd/go/internal/web/http.go:127 +0x509
cmd/go/internal/modfetch.(*proxyRepo).getBody(0xc000322540, {0xc00030e5a0, 0x2a})
	/Users/rsc/go/src/cmd/go/internal/modfetch/proxy.go:260 +0x13e
cmd/go/internal/modfetch.(*proxyRepo).getBytes(0xc00011c150, {0xc00030e5a0, 0xc0001c65c0})
	/Users/rsc/go/src/cmd/go/internal/modfetch/proxy.go:245 +0x4b
cmd/go/internal/modfetch.(*proxyRepo).Stat(0xc000322540, {0xc00011c150, 0xc00011c150})
	/Users/rsc/go/src/cmd/go/internal/modfetch/proxy.go:353 +0x8b
	/Users/rsc/go/src/cmd/go/internal/modfetch/cache.go:230 +0x82
cmd/go/internal/par.(*Cache).Do(0xc0003162b0, {0x141d2c0, 0xc00030a340}, 0xc0001c67b8)
	/Users/rsc/go/src/cmd/go/internal/par/work.go:128 +0xc3
cmd/go/internal/modfetch.(*cachingRepo).Stat(0xc0003162a0, {0xc00011c150, 0x22})
	/Users/rsc/go/src/cmd/go/internal/modfetch/cache.go:224 +0x9d
cmd/go/internal/modload.queryProxy({0x1558140, 0xc0000261c8}, {0xc00002c0f8, 0x18}, {0xc00012c040, 0xc0001c6a88}, {0xc00011c150, 0x0}, {0x0, 0x0})
	/Users/rsc/go/src/cmd/go/internal/modload/query.go:139 +0xe35
cmd/go/internal/modload.Query.func1({0xc00002c0f8, 0xc000318e08})
	/Users/rsc/go/src/cmd/go/internal/modload/query.go:71 +0x6d
	/Users/rsc/go/src/cmd/go/internal/modfetch/proxy.go:163 +0xb2
cmd/go/internal/modload.Query({0x1558140, 0xc0000261c8}, {0xc00012c040, 0x26}, {0xc00011c150, 0xe400000000000003}, {0x0, 0xc0001d20d0}, 0xc0001c6c48)
	/Users/rsc/go/src/cmd/go/internal/modload/query.go:70 +0xc5
	/Users/rsc/go/src/cmd/go/internal/modload/build.go:250 +0xb0
cmd/go/internal/modload.moduleInfo({0x1558140, 0xc0000261c8}, 0xc000020370, {{0xc00012c040, 0xc0001c6f88}, {0xc00011c150, 0xc0001c6e58}}, 0x0)
	/Users/rsc/go/src/cmd/go/internal/modload/build.go:305 +0x60a
cmd/go/internal/modload.listModules({0x1558140, 0xc0000261c8}, 0xc000020370, {0xc0000200e0, 0x1, 0x0}, 0x0)
	/Users/rsc/go/src/cmd/go/internal/modload/list.go:225 +0x158d
cmd/go/internal/modload.ListModules({0x1558140, 0xc0000261c8}, {0xc0000200e0, 0x1, 0x1}, 0x0)
	/Users/rsc/go/src/cmd/go/internal/modload/list.go:38 +0x93
cmd/go/internal/list.runList({0x1558140, 0xc0000261c8}, 0xc0000284b0, {0xc0000200e0, 0x44, 0x1})
	/Users/rsc/go/src/cmd/go/internal/list/list.go:467 +0x279f
main.invoke(0x17d9aa0, {0xc0000200b0, 0x4, 0x4})
	/Users/rsc/go/src/cmd/go/main.go:216 +0x2f6
	/Users/rsc/go/src/cmd/go/main.go:173 +0x78e
package semver // import ""

Package semver implements comparison of semantic version strings. In this
package, semantic version strings must begin with a leading "v", as in

It looks like go doc invokes go tool doc which invokes go list.
So far so good.
But go list should not need to use the network:
all I want is the docs for the package in the current directory.
We should remove the network usage.

/cc @bcmills @jayconrod @matloob

@rsc rsc added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 14, 2021
@rsc rsc added this to the Go1.17 milestone Jul 14, 2021
Copy link

bcmills commented Jul 14, 2021

The go list invocation is here:

cmd := exec.Command("go", "list", "-m", "-f={{.Path}}\t{{.Dir}}", "all")

cmd/doc is using go list -m because it is doing the same kind of fuzzy searching that gopls and goimports use: it can't just go list a specific package because it doesn't know which package you want.

go list -m needs network access because it collects all of the information about a module needed for the complete JSON output even if the user is only requesting a few locally-available fields (#29666, #29869, #42723). So I think in the general case this is a duplicate of #29666, which is going to require a fair amount of work to fix.

Copy link

bcmills commented Jul 14, 2021

That said, for the specific case where the exact package directory is known, cmd/doc should probably skip go list -m all (which unnecessarily loads the full module graph), and instead go list only that specific package.

@jayconrod jayconrod modified the milestones: Go1.17, Go1.18 Jul 29, 2021
@dmitshur dmitshur added the GoCommand cmd/go label Nov 10, 2021
@dmitshur dmitshur modified the milestones: Go1.18, Backlog Nov 10, 2021
@bcmills bcmills changed the title cmd/go: http activity during 'go doc' cmd/go,cmd/doc: http activity during 'go doc' Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
None yet

No branches or pull requests

4 participants