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: expected 'package', found 'EOF' errors with module indexing enabled on WSL2 #54651

Open
jhaumont opened this issue Aug 24, 2022 · 28 comments
Labels
GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jhaumont
Copy link

jhaumont commented Aug 24, 2022

What version of Go are you using (go version)?

$ go version
go version go1.19 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jhaumont/.cache/go-build"
GOENV="/home/jhaumont/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jhaumont/go/pkg/mod"
GONOPROXY="github.com/blablacar"
GONOSUMDB="github.com/blablacar"
GOOS="linux"
GOPATH="/home/jhaumont/go"
GOPRIVATE="github.com/blablacar"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/jhaumont/bin/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/jhaumont/bin/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1850192189=/tmp/go-build -gno-record-gcc-switches"

What did you do?

When installing 1.19 go version & reinstall/update the additional go tools like gopls & dlv, I have an issue with delve and the package https://github.com/hashicorp/golang-lru/tree/master/simplelru.
So, I can't install delve. But if I use the 1.18.5 version of go, I have no issue and I can install the last delve version (1.9.0)

But if I use GODEBUG=goindex=0, it works :)

Reproduce:
I try to do a fresh install of go (with 1.19.0) and then, install delve.

  • Install go:
rm -rf ${HOME}/bin/go
cd "$(mktemp -d)"
wget https://go.dev/dl/go1.19.linux-amd64.tar.gz
tar -C ${HOME}/bin -xzf go1.19.linux-amd64.tar.gz
  • Install devel:
go install -v github.com/go-delve/delve/cmd/dlv@latest

What did you expect to see?

No error, devel is correctly installed

What did you see instead?

pkg/mod/github.com/hashicorp/golang-lru@v0.5.4/simplelru/lru.go:1:1: expected 'package', found 'EOF'

@jhaumont
Copy link
Author

jhaumont commented Aug 24, 2022

@jhaumont jhaumont changed the title affected/package: cmd/go - modindex - Can't install delve with go 1.19 cmd/go - modindex - Can't install delve with go 1.19 Aug 24, 2022
@jhaumont jhaumont changed the title cmd/go - modindex - Can't install delve with go 1.19 cmd/go - modindex: Can't install delve with go 1.19 Aug 24, 2022
@bcmills bcmills added this to the Go1.20 milestone Aug 24, 2022
@dr2chase
Copy link
Contributor

Assigned @bcmills for now, anyone looking at this should know that this is not reproducible in general (I tried with 1.19 and tip on macOS and Linux), but there was nonetheless a problem, which is linked to the delve bug and referenced files above. So it remains open.

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 24, 2022
@jhaumont
Copy link
Author

By the way @dr2chase, I work with Debian on WSL.

@bcmills bcmills changed the title cmd/go - modindex: Can't install delve with go 1.19 cmd/go: error installing delve with go 1.19 with module indexing enabled Aug 25, 2022
@jhaumont
Copy link
Author

jhaumont commented Sep 8, 2022

Hello
I face the same issue with 2 new packages (not link to delve) on an internal go projet:
../../go/pkg/mod/github.com/armon/go-radix@v1.0.0/radix.go:1:1: expected 'package', found 'EOF' ../../go/pkg/mod/github.com/mitchellh/mapstructure@v1.5.0/decode_hooks.go:1:1: expected 'package', found 'EOF'
Using GODEBUG=goindex=0 fix the issue

@bcmills
Copy link
Contributor

bcmills commented Sep 8, 2022

@jhaumont, just to rule out filesystem weirdness, what filesystem are you using for /home/jhaumont/go/pkg/mod?

@bcmills
Copy link
Contributor

bcmills commented Sep 8, 2022

And does running go clean -cache also fix the issue (without GODEBUG=goindex=0) when it happens?

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 8, 2022
@jhaumont
Copy link
Author

jhaumont commented Sep 9, 2022

@bcmills I'm on WSL. This is the result of mount | column -t command:
/dev/sdc on / type ext4 (rw,relatime,discard,errors=remount-ro,data=ordered)
And for the second question, the answer is no (I already test it before opening the issue)

@aarzilli
Copy link
Contributor

aarzilli commented Sep 9, 2022

Is this WSL1 or WSL2?

@jhaumont
Copy link
Author

jhaumont commented Sep 9, 2022

@aarzilli WSL2 with debian

@bcmills bcmills removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 19, 2022
@bcmills
Copy link
Contributor

bcmills commented Sep 19, 2022

This is currently the only report we have of this kind of corruption. It's not clear to me whether this is a bug in Go, a bug in WSL2, or both. Moving to the Backlog pending more user reports and/or test failures that might shed some light for debugging.

@bcmills bcmills modified the milestones: Go1.20, Backlog Sep 19, 2022
@bcmills bcmills removed their assignment Sep 19, 2022
@bcmills bcmills changed the title cmd/go: error installing delve with go 1.19 with module indexing enabled cmd/go: expected 'package', found 'EOF' errors with module indexing enabled on WSL2 Sep 29, 2022
@Obasoro
Copy link

Obasoro commented Jan 2, 2023

I have go on both my system and I am having the same issue after installing go and trying to run a go file "go:1:1: expected 'package', found 'EOF'"

package main
import
"fmt"
"os"

func main() {
var s, sep string
for i := 1; i < len(os.Args); i++ {
s += sep + os.Args[i]
sep = ""
}
fmt.Println(s)

}

@jhaumont
Copy link
Author

@bcmills @Obasoro on my side, I have wiped out my WSL and it works normally. I ve no idea why 😕

@ghost
Copy link

ghost commented Feb 11, 2023

I've faced the same issue today.

If I run go build with GOPATH="$(realpath ../gopath)", the command fails. However, I was able to resolve the error by several workarounds:

  1. Setting GOPATH to somewhere else, such as ../../gopath. I have no idea what makes the difference.
  2. By using GODEBUG=goindex=0.
  3. Locating the building directory somewhere else (see below on this).

Something about the location of building directory appears to cause the error. First of all, the problem is only caused when the building directory is either ~/aur/yay/src/yay-11.3.2, ~/aur/yay/src/yay, ~/aur/yay/src/foobarbaz, or anything else of that kind. Otherwise, I wasn't able to reproduce the error, e.g. the building works perfectly in ~/aur/yay/yay. It seems like there's something special about ~/aur/yay/src.

Permissions don't seem to cause the error. I've removed and created ~/aur several times.

go version

go version go1.20 linux/amd64

go env

output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/azat/.cache/go-build"
GOENV="/home/azat/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/azat/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/azat/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/azat/aur/yay/src/foo/barbaz/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1292885877=/tmp/go-build -gno-record-gcc-switches"

what I did

mkdir -p aur/yay/src
cd aur/yay/src
git clone https://github.com/Jguer/yay
cd yay
GOPATH="$(realpath ../gopath)" go build

what I expected to see

output
go: downloading github.com/Jguer/aur v1.1.3
go: downloading github.com/Jguer/go-alpm/v2 v2.1.2
go: downloading github.com/Jguer/votar v1.0.0
go: downloading github.com/Morganamilo/go-srcinfo v1.0.0
go: downloading github.com/deckarep/golang-set/v2 v2.1.0
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/leonelquinteros/gotext v1.5.1
go: downloading github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
go: downloading github.com/adrg/strutil v0.3.0
go: downloading golang.org/x/term v0.3.0
go: downloading golang.org/x/sys v0.3.0
go: downloading github.com/itchyny/gojq v0.12.11
go: downloading github.com/ohler55/ojg v1.15.0
go: downloading golang.org/x/text v0.5.0
go: downloading github.com/itchyny/timefmt-go v0.1.5

what I saw

output
go: downloading github.com/Jguer/aur v1.1.3
go: downloading github.com/Jguer/go-alpm/v2 v2.1.2
go: downloading github.com/Jguer/votar v1.0.0
go: downloading github.com/Morganamilo/go-srcinfo v1.0.0
go: downloading github.com/deckarep/golang-set/v2 v2.1.0
go: downloading github.com/leonelquinteros/gotext v1.5.1
go: downloading github.com/pkg/errors v0.9.1
go: downloading github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
go: downloading github.com/adrg/strutil v0.3.0
go: downloading golang.org/x/term v0.3.0
go: downloading golang.org/x/sys v0.3.0
go: downloading github.com/itchyny/gojq v0.12.11
go: downloading github.com/ohler55/ojg v1.15.0
go: downloading golang.org/x/text v0.5.0
go: downloading github.com/itchyny/timefmt-go v0.1.5
../gopath/pkg/mod/github.com/!jguer/votar@v1.0.0/pkg/vote/aur.go:1:1: expected 'package', found 'EOF'
../gopath/pkg/mod/github.com/!morganamilo/go-pacmanconf@v0.0.0-20210502114700-cff030e927a5/cmd.go:1:1: expected 'package', found 'EOF'
../gopath/pkg/mod/github.com/!morganamilo/go-srcinfo@v1.0.0/examples_test.go:1:1: expected 'package', found 'EOF'
../gopath/pkg/mod/github.com/adrg/strutil@v0.3.0/example_test.go:1:1: expected 'package', found 'EOF'
../gopath/pkg/mod/github.com/adrg/strutil@v0.3.0/metrics/examples_test.go:1:1: expected 'package', found 'EOF'

@ghost
Copy link

ghost commented Feb 11, 2023

The problem has been resolved after I deleted go-build cache in ~/.cache/go-build

@Windeal
Copy link

Windeal commented Feb 15, 2023

The problem has been resolved after I deleted go-build cache in ~/.cache/go-build

I've faced the same issue today.
And solved with your method, thanks

@aarzilli
Copy link
Contributor

@azat-reason @Windeal are you using WSL2?

@timohn
Copy link

timohn commented Feb 24, 2023

The problem has been resolved after I deleted go-build cache in ~/.cache/go-build

Had the issue on centOS 7.
Fixed it for me either - thank you!

@GMsure
Copy link

GMsure commented Apr 6, 2023

Well I was having a lot of xxx.go:1:1: expected 'package', found 'EOF' problems when I went to build the kubectl-debug tool in WSL2
After deleting the cache directory under gowork/pkg/mod and all the packages that prompted for EOF in the file header, I re-make and solved the problem
In the situation I was in, this command was executed in the ~/gowork/pkg/mod directory: sudo rm -rf cache sigs.k8s.io github.com golang.org k8s.io

@jhaumont
Copy link
Author

jhaumont commented May 4, 2023

Hello
I just update to go 1.20 and no issue on my side. So I only have the issue with the update from 1.18 to 1.19

@ghoulsec
Copy link

ghoulsec commented May 6, 2023

Hi, I just updated to 1.20, no problem on my side. So I only have problems with updates from 1.18 to 1.19
I am also version 20, but I am in the Windows version of vscode environment
image

@youguanxinqing
Copy link

The problem has been resolved after I deleted go-build cache in ~/.cache/go-build

It's helpful! Works for me after go clean -cache on WSL1.

@Jack-Can
Copy link

Using VS Code for GO, and faced the same issue. Saving the file 'Ctrl+S' on Windows fixed the issue.

@ChennSun
Copy link

我删除了go-build缓存后问题已经解决~/.cache/go-build

nice, solved my problem

@newnetmp3
Copy link

currently having this issue on Linux Mint 21.2 when run as a normal user:
../go/pkg/mod/github.com/h2non/bimg@v1.1.5/type.go:1:1: expected 'package', found 'EOF'

runs fine when run as root, fails in sudo

@Moonyongjung
Copy link

The problem has been resolved after I deleted go-build cache in ~/.cache/go-build

Thanks, it is helpful.

@dimisjim
Copy link

dimisjim commented Feb 5, 2024

This can also be due to go files in the module, not having the package declaration: https://stackoverflow.com/a/38812470/3263374

@zhengsc01
Copy link

go clean -cache works for me on WSL 2. Thanks for sharing!

@whatisor
Copy link

whatisor commented Aug 1, 2024

The problem has been resolved after I deleted go-build cache in ~/.cache/go-build

It's helpful! Works for me after go clean -cache on WSL1.

Full clean by these if folder exists

rm -rf ~/.cache/go-build
rm -rf ~/.cache/golangci-lint
go clean -modcache
go mod tidy

Then it should be fresh for go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests