golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.61k stars 17.61k forks source link

cmd/godoc: confused by symlinks in GOROOT: godoc: corpus fstree is nil #15049

Closed benbarbour closed 6 years ago

benbarbour commented 8 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)? go version go1.6 linux/amd64
  2. What operating system and processor architecture are you using (go env)? GOARCH="amd64" GOBIN="" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/me/Code/go" GORACE="" GOROOT="/usr/lib/go" GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" GO15VENDOREXPERIMENT="1" CC="gcc" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0" CXX="g++" CGO_ENABLED="1"
  3. What did you do? go get golang.org/x/tools/cmd/godoc sudo -E go install golang.org/x/tools/cmd/godoc godoc -http=":8080"
  4. What did you expect to see? godoc running on the command line, listening to HTTP requests
  5. What did you see instead? "2016/03/31 11:15:45 godoc: corpus fstree is nil", followed by program exit with status code -1
  6. Other notes
    • It was working when I was running go 1.5, I added the ubuntu-lxc/lxd-stable ppa and upgraded to go 1.6.
    • I tried running go get with --update, and then tried removing all references I could find to godoc and the installing again using the commands from question # 3.
    • which godoc gives "/usr/lib/go/bin/godoc"
    • godoc net/http prints the documentation on the command line, as expected.
mwhudson commented 8 years ago

Unfortunately godoc gets confused by the symlinks in $GOROOT. The debian packaging of godoc carries a patch that hacks around this, I guess some kind of better solution would be, well, better.

benbarbour commented 8 years ago

Hmmm... in the meantime, could you point me to the patch and/or package with the fix? Might help other people searching for this bug too.

benbarbour commented 8 years ago

Here's a partially functioning workaround for anyone who cares.

If I run godoc -http=":8080 -goroot /usr/share/go (where /usr/share/go is the path that some of the symlinks in GOROOT point to) the server starts. It can't find the "Documents" page so I can't view "Effective Go" and friends locally, but at least I can navigate around package docs, including my own packages.

tomdee commented 8 years ago

I got this working by removing the docs symlink and taking a copy of the docs source..

in /usr/lib/go-1.6

sudo mv doc doc.old
sudo cp -ra ../../share/doc/golang-1.6-doc/html doc
gopherbot commented 7 years ago

CL https://golang.org/cl/45096 mentions this issue.

bradfitz commented 7 years ago

Repro instructions:

$ mkdir $HOME/gorootsym_under
$ cd $HOME/gorootsym_under
$ ln -s $GOROOT/bin
$ ln -s $GOROOT/src
$ ln -s $GOROOT/pkg
$ ls -l $HOME/gorootsym_under/
total 0
lrwxrwxrwx 1 bradfitz bradfitz 21 Jul 14 19:06 bin -> /home/bradfitz/go/bin
lrwxrwxrwx 1 bradfitz bradfitz 21 Jul 14 19:06 pkg -> /home/bradfitz/go/pkg
lrwxrwxrwx 1 bradfitz bradfitz 21 Jul 14 19:06 src -> /home/bradfitz/go/src

$ GOROOT=$HOME/gorootsym_under GOPATH= godoc -http=:6060 -v
2017/07/14 19:06:44 godoc: corpus fstree is nil 
gopherbot commented 7 years ago

Change https://golang.org/cl/53634 mentions this issue: godoc: don't try to follow all symlinks

gopherbot commented 7 years ago

Change https://golang.org/cl/57870 mentions this issue: [release-branch.go1.9] godoc: don't try to follow all symlinks

rsc commented 6 years ago

I think this is basically working as intended. Every time anyone tries to make godoc do more with symlinks it ends up chasing its own tail. Symlinks in Go file trees should just be disallowed, honestly.

zigo101 commented 6 years ago

so this will be fixed in go 1.10?

ianlancetaylor commented 6 years ago

1.10 will work as well or as poorly as 1.9.

zigo101 commented 6 years ago

It is not even poorly. It doesn't work at all now. I don't know what have changed in the past several months. I often used godoc -http :9999 to open a local doc server several months ago. But yesterday, I re-run this command again, I found it didn't work any more.

Here is the the command log:

myname@localhost:~$ godoc -http=:8080 
2017/11/30 07:16:39 newDirectory(/): stat /usr/local/go: no such file or directory
2017/11/30 07:16:39 godoc: corpus fstree is nil
myname@localhost:~$
myname@localhost:~$ godoc -http=:8080 -goroot /home/myname/gosdk
(will stuck here for ever, cpu usage is 0%, http://localhost:8080/ is unable to connect. I must use ctrl-c to stop it)
^C
myname@localhost:~$
myname@localhost:~$ GOROOT=/home/myname/gosdk
myname@localhost:~$ GOPATH=/home/myname/go
myname@localhost:~$ godoc -http=:8080 
2017/11/30 07:21:35 newDirectory(/): stat /usr/local/go: no such file or directory
2017/11/30 07:21:35 godoc: corpus fstree is nil

The only change from my side is I removed the GOPATH and GOROOT envs from .bashrc. But it still doesn't work when I set the two envs back.

There is not any symlink involved in my Go setup.

Is there a workable workaround?

davecheney commented 6 years ago

guess: go install .../cmd/godoc to rebuild godoc. It looks like the value encoded in your current godoc command is hard coded to look for GOROOT at /usr/local/go

On Thu, Nov 30, 2017 at 11:24 PM, Go101 notifications@github.com wrote:

It is not even poorly. It doesn't work at all now. I don't know what have changed in the past several months. I often used `godoc -http :9999" to open a local doc server several months ago. But I yesterday, I re-run this command again, I found it didn't work any more.

Here is the the command log:

myname@localhost:~$ godoc -http=:8080 2017/11/30 07:16:39 newDirectory(/): stat /usr/local/go: no such file or directory 2017/11/30 07:16:39 godoc: corpus fstree is nil myname@localhost:~$ myname@localhost:~$ godoc -http=:8080 -goroot /home/myname/gosdk (will stuck here for ever, cpu usage is 0%, I must use ctrl-c to stop it) ^C myname@localhost:~$ myname@localhost:~$ GOROOT=/home/myname/sdks/go myname@localhost:~$ GOPATH=/home/myname/go myname@localhost:~$ godoc -http=:8080 2017/11/30 07:21:35 newDirectory(/): stat /usr/local/go: no such file or directory 2017/11/30 07:21:35 godoc: corpus fstree is

The only change from my side is I removed the GOPATH and GOROOT envs from .bashrc. But it still doesn't work when I set the two envs back.

There is not any symlink involved in my Go setup.

Is there a workable workaround?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/golang/go/issues/15049#issuecomment-348173734, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAcA3v12E_6F8Qm4euAw_XvHEl4Z25kks5s7p6CgaJpZM4H9CU1 .

zigo101 commented 6 years ago

OK, add export when setting back the GOROOT env works.

myname@localhost:~$ export GOROOT=/home/myname/gosdk
myname@localhost:~$ godoc -http=:8080 

It looks godoc -http :8080 -goroot /home/myname/gosdk also works. I don't know why the last run is stuck.

So, godoc doesn't work if GOROOT is not set. Bug? And will be fixed on 1.10?

zigo101 commented 6 years ago

@davecheney I never built godoc. which godoc prints /home/myname/gosdk/bin/godoc.

davecheney commented 6 years ago

So, godoc doesn't work if GOROOT is not set. Bug? And will be fixed on 1.10?

A some point my guess is the value of runtime.GOROOT() is going to be used, and the fallback for that function is the GOROOT that the Go compiler that built this program knew at the time it was compiled.

On Thu, Nov 30, 2017 at 11:44 PM, Go101 notifications@github.com wrote:

OK, add export when setting back the GOROOT env works.

myname@localhost:~$ export GOROOT=/home/myname/gosdk myname@localhost:~$ godoc -http=:8080

It looks godoc -http :8080 -goroot /home/myname/gosdk also works. I don't know why the last run is stuck.

So, godoc doesn't work if GOROOT is not set. Bug? And will be fixed on 1.10?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/golang/go/issues/15049#issuecomment-348177925, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAcA8sCRZiUnxcuQhDJjgf9WA_wBDLrks5s7qMsgaJpZM4H9CU1 .

tsuna commented 6 years ago

I can confirm godoc doesn't work if GOROOT isn't set with go1.10.1.

mvdan commented 6 years ago

@tsuna if that's true, please open a separate issue with the details of your environment and how to reproduce the issue. This issue is old and closed, so it's not the best place to discuss it.

tsuna commented 6 years ago

This is tracked under #23445.