Description
I'm doing GOPATH-based vendoring, where my GOPATH is basically "$MyVendorDir:$HOME". This works perfectly fine most of the time. However in some cases, when the version of a package directly in GOPATH differs significantly from the vendored version, it doesn't. I think this highlights a race condition or other issue in the "go" tool when doing paralell compilation that doesn't show up when the vendored version of a package matches the "default" version.
These are my paths; there is a vendored github.com/calmh/xdr package, and I remove the pkg dirs in both GOPATH components before building:
jb@syno:~/s/g/s/syncthing $ go version
go version go1.5.2 darwin/amd64
jb@syno:~/s/g/s/syncthing $ echo $GOPATH
/Users/jb/src/github.com/syncthing/syncthing/Godeps/_workspace:/Users/jb
jb@syno:~/s/g/s/syncthing $ pwd
/Users/jb/src/github.com/syncthing/syncthing
jb@syno:~/s/g/s/syncthing $ ls -l Godeps/_workspace/src/github.com/calmh/xdr
total 112
-rw-r--r-- 1 jb staff 1059 Feb 1 08:17 LICENSE
-rw-r--r-- 1 jb staff 660 Feb 1 08:17 README.md
...
-rw-r--r-- 1 jb staff 675 Feb 1 08:17 writer_ipdr.go
-rw-r--r-- 1 jb staff 365 Feb 1 08:17 writer_xdr.go
jb@syno:~/s/g/s/syncthing $ rm -r Godeps/_workspace/pkg ~/pkg
When I then build, I hit this:
jb@syno:~/s/g/s/syncthing $ go install ./cmd/...
# github.com/syncthing/syncthing/cmd/stfinddevice
github.com/syncthing/syncthing/lib/discover.Relay.EncodeXDR: type.github.com/calmh/xdr.Writer: not defined
github.com/syncthing/syncthing/lib/discover.Relay.AppendXDR: type.github.com/calmh/xdr.AppendWriter: not defined
github.com/syncthing/syncthing/lib/discover.Relay.AppendXDR: type.github.com/calmh/xdr.Writer: not defined
github.com/syncthing/syncthing/lib/discover.Relay.AppendXDR: type.*github.com/calmh/xdr.AppendWriter: not defined
github.com/syncthing/syncthing/lib/discover.Relay.EncodeXDRInto: github.com/calmh/xdr.(*Writer).WriteString: not defined
github.com/syncthing/syncthing/lib/discover.Relay.EncodeXDRInto: github.com/calmh/xdr.(*Writer).WriteUint32: not defined
github.com/syncthing/syncthing/lib/discover.Relay.EncodeXDRInto: type.github.com/calmh/xdr.XDRError: not defined
github.com/syncthing/syncthing/lib/discover.(*Relay).DecodeXDR: type.github.com/calmh/xdr.Reader: not defined
github.com/syncthing/syncthing/lib/discover.(*Relay).UnmarshalXDR: type.github.com/calmh/xdr.Reader: not defined
github.com/syncthing/syncthing/lib/discover.(*Relay).DecodeXDRFrom: github.com/calmh/xdr.(*Reader).ReadStringMax: not defined
github.com/syncthing/syncthing/lib/discover.(*Relay).DecodeXDRFrom: github.com/calmh/xdr.(*Reader).ReadUint32: not defined
github.com/syncthing/syncthing/lib/discover.(*Relay).DecodeXDRFrom: type.github.com/calmh/xdr.XDRError: not defined
type.func(*github.com/calmh/xdr.Reader) error: type.*github.com/calmh/xdr.Reader: not defined
type.func(*github.com/calmh/xdr.Writer) (int, error): type.*github.com/calmh/xdr.Writer: not defined
type.func(*github.com/syncthing/syncthing/lib/discover.Relay, *github.com/calmh/xdr.Reader) error: type.*github.com/calmh/xdr.Reader: not defined
type.func(*github.com/syncthing/syncthing/lib/discover.Relay, *github.com/calmh/xdr.Writer) (int, error): type.*github.com/calmh/xdr.Writer: not defined
type.func(github.com/syncthing/syncthing/lib/discover.Relay, *github.com/calmh/xdr.Writer) (int, error): type.*github.com/calmh/xdr.Writer: not defined
panic: runtime error: index out of range
goroutine 1 [running]:
cmd/link/internal/ld.defgotype(0xc821bfb180, 0x5)
/usr/local/go/src/cmd/link/internal/ld/dwarf.go:984 +0x4b42
cmd/link/internal/ld.defdwsymb(0x0, 0xc821c20ec0, 0x38, 0x61, 0x0, 0x0, 0x0, 0xc821bfb180)
/usr/local/go/src/cmd/link/internal/ld/dwarf.go:1447 +0x4be
cmd/link/internal/ld.genasmsym(0x2c85c0)
/usr/local/go/src/cmd/link/internal/ld/lib.go:1858 +0x6d6
cmd/link/internal/ld.Dwarfemitdebugsections()
/usr/local/go/src/cmd/link/internal/ld/dwarf.go:2179 +0xa46
cmd/link/internal/amd64.asmb()
/usr/local/go/src/cmd/link/internal/amd64/asm.go:665 +0x8ba
cmd/link/internal/ld.Ldmain()
/usr/local/go/src/cmd/link/internal/ld/pobj.go:246 +0x1ed6
cmd/link/internal/amd64.Main()
/usr/local/go/src/cmd/link/internal/amd64/obj.go:44 +0x19
main.main()
/usr/local/go/src/cmd/link/main.go:26 +0x189
jb@syno:~/s/g/s/syncthing $
There's two strange things here. The first is the compile errors complaining about types not being defined in github.com/calmh/xdr. This is because it's using the version from ~/src (the second component of GOPATH), not the vendored one (the first component). The second is the panic, which doesn't look good but also doesn't always happen...
Looking at what it actually produced before erroring we can see that it built both the XDR package at the top level GOPATH and the vendored version (and they differ, in this case) - notice the timestamps on xdr.a
and the fact that I nuked both pkg dirs before building:
jb@syno:~/syno/g/s/syncthing $ ls -l Godeps/_workspace/pkg/darwin_amd64/github.com/calmh
total 336
-rw-r--r-- 1 jb staff 5182 Feb 1 08:34 du.a
-rw-r--r-- 1 jb staff 33230 Feb 1 08:34 luhn.a
-rw-r--r-- 1 jb staff 123500 Feb 1 08:34 xdr.a
jb@syno:~/s/g/s/syncthing $ ls -l ~/pkg/
total 0
drwxr-xr-x 3 jb staff 102 Feb 1 08:34 darwin_amd64/
jb@syno:~/s/g/s/syncthing $ ls -l ~/pkg/darwin_amd64/github.com/calmh/
total 152
-rw-r--r-- 1 jb wheel 77688 Feb 1 08:34 xdr.a
jb@syno:~/s/g/s/syncthing $
The XDR package is used by many things in "./cmd/..." - is there maybe some race condition around that when the build parallellizes things?
This all happens "now and then", and I finally solve it by touching source files, repeatedly running go install and so on to try to narrow it down ... and then it compiles just fine again... When writing this up, it started working when I used "go install -v -x" to find out what exact command builds the "wrong" version of the XDR package, without actually changing anything on disk, and now I cant reproduce it again. So I don't have a minimal reproducer, but there's something weird going on here. :(