Skip to content

panic: runtime error: index out of range, goroutine 89 [running] #1759

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

Closed
YanRyan opened this issue Jul 31, 2019 · 26 comments
Closed

panic: runtime error: index out of range, goroutine 89 [running] #1759

YanRyan opened this issue Jul 31, 2019 · 26 comments
Assignees
Labels
triage/duplicate Indicates an issue is a duplicate of other open issue. triage/support Indicates an issue that is a support question.

Comments

@YanRyan
Copy link

YanRyan commented Jul 31, 2019

Hello, I got this problem when I use operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
1564563911787

I just follow the ReadMe, Quick Start.
1564564168590

@YanRyan
Copy link
Author

YanRyan commented Jul 31, 2019

I use brew install operator-sdk. MacOs

@camilamacedo86
Copy link
Contributor

camilamacedo86 commented Jul 31, 2019

Hi @YanRyan,

It shows duplicated of #1734. Please, could you check and if yes close this one? Also, note that here (#1734 will find the steps to solve it.

@YanRyan
Copy link
Author

YanRyan commented Aug 1, 2019

I am sorry to say that, '#1734' this didn't solve my problem.
At first, this is my go env
1564642546044

Then I change my GOROOT to '/usr/local/go', I still got this problem. It's panic at 'Created pkg/apis/asia/group.go'. I sign it use red frame.
1564642498808

Then I try again, follow the issues #1765 I change my GOROOT to '/url/lib/golang', It panic at 'Created deploy/crds '. I sign it use red frame.
1564642440467

Is there anything I didn't do correct or just the env promblem?

@YanRyan
Copy link
Author

YanRyan commented Aug 1, 2019

Hello, I try to reinstall go, it still have this problem. What should I do.
1564648054328
?

@camilamacedo86
Copy link
Contributor

Hi @YanRyan.

Did you try it #1545 (comment) ?

@YanRyan
Copy link
Author

YanRyan commented Aug 1, 2019

Yes, I try this. I reinstall go and the default location is '/usr/local/go'

@YanRyan
Copy link
Author

YanRyan commented Aug 1, 2019

Hi @YanRyan.

Did you try it #1545 (comment) ?
Yes, I try this. I reinstall go and the default location is '/usr/local/go'. It still panic. I saw you have the same problem, you fix it by set GOROOT?

@joelanford
Copy link
Member

@YanRyan How are you installing go? If you use Homebrew to install operator-sdk, it will also install the go brew formula, which may be conflicting with your existing Go installation.

If which go reports /usr/local/go/bin/go, then your GOROOT needs to be set to /usr/local/go.
If which go reports /usr/local/Cellar/go/1.12.7/bin/go then your GOROOT needs to be set to /usr/local/Cellar/go/1.12.7/libexec

My advice is to make sure you only have one go installation on your system, in which case you should not have to explicitly set GOROOT.

@joelanford joelanford self-assigned this Aug 1, 2019
@joelanford joelanford added triage/support Indicates an issue that is a support question. triage/duplicate Indicates an issue is a duplicate of other open issue. labels Aug 1, 2019
@joelanford
Copy link
Member

@YanRyan I'm going to close this since it seems like a duplicate of #1545, but we'll be happy to help you keep debugging your go environment my above comment doesn't resolve it.

@YanRyan
Copy link
Author

YanRyan commented Aug 2, 2019

I'm so sorry to say that, I still have this problem.
I delete all the go installation then I use go1.12.7.darwin-amd64.pkg install it. Should I need to reinstall the operator-sdk?
The which go reports /usr/local/go/bin/go, and go env GOROOT reports /usr/local/go
More information please check the image.
image

@YanRyan
Copy link
Author

YanRyan commented Aug 2, 2019

It drives me crazy. I use brew uninstall operator-sdk then I git clone && make install the operator-sdk it still have this problem.

@YanRyan
Copy link
Author

YanRyan commented Aug 2, 2019

I install the go and operator-sdk in CentOS 7.5, then I create the project success. I think this the problem of my MacOs, maybe there still have env problem. Tanks all!

@mandymchu
Copy link

mandymchu commented Aug 21, 2019

I hit the similar issue on mac. Reinstalled go and operator-sdk, but still met the error:

$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
INFO[0000] Generating api version app.example.com/v1alpha1 for kind AppService.
INFO[0000] Created pkg/apis/app/group.go
panic: runtime error: index out of range

goroutine 69 [running]:
golang.org/x/tools/imports.(*moduleResolver).scan.func1(0xc000767880, 0x17, 0x4, 0xc00076b040, 0x37)
	pkg/mod/golang.org/x/[email protected]/imports/mod.go:254 +0x9df
golang.org/x/tools/internal/gopathwalk.(*walker).walk(0xc0004c0480, 0xc00076b040, 0x41, 0x0, 0xc00076b040, 0x41)
	pkg/mod/golang.org/x/[email protected]/internal/gopathwalk/walk.go:175 +0xf5
golang.org/x/tools/internal/fastwalk.(*walker).onDirEnt(0xc0007f4990, 0xc0008389c0, 0x37, 0xc0000500e0, 0x9, 0xc000000000, 0x0, 0x0)
	pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:168 +0xbb
golang.org/x/tools/internal/fastwalk.readDir(0xc0008389c0, 0x37, 0xc0007b7e88, 0x0, 0x0)
	pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk_unix.go:68 +0x212
golang.org/x/tools/internal/fastwalk.(*walker).walk(0xc0007f4990, 0xc0008389c0, 0x37, 0x1, 0x1, 0x0)
	pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:195 +0x6a
golang.org/x/tools/internal/fastwalk.(*walker).doWork(0xc0007f4990, 0xc00080cf50)
	pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:134 +0x14d
created by golang.org/x/tools/internal/fastwalk.Walk
	pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:81 +0x21d

Some info for my settings:

  • go version: go version go1.12.9 darwin/amd64
  • which go: /usr/local/bin/go
  • operator-sdk version: v0.10.0
  • GOROOT=/usr/local/go

Any idea for fix it? Thanks.

@joelanford
Copy link
Member

joelanford commented Aug 21, 2019

@mandymchu How did you install operator-sdk and go?

@mandymchu
Copy link

mandymchu commented Aug 21, 2019

@joelanford Used brew install operator-sdk and go1.12.9.darwin-amd64.pkg

@mandymchu
Copy link

I tried reinstalling go via go1.12.9.darwin-amd64.tar.gz, but it did not help as well

@joelanford
Copy link
Member

Hmm I thought I was able to get things working originally on my Mac, but now I'm getting a panic trying all sorts of combinations of ways of installing Go and operator-sdk. I'm going to re-open this until we get to the bottom of this.

@estroz @hasbro17 @theishshah @fabianvf @jmrodri Do any of you all have this working on a Mac? If so, what's your setup?

@mandymchu Either way, your environment looks like it could be broken. Your GOROOT is /usr/local/go, so I would expect which go to be /usr/local/go/bin/go, not /usr/local/bin/go

My guess is that you have a self-installed Go (as you mentioned) but ALSO a Go installation from brew as a result of operator-sdk's brew formula declaring a dependency on the go brew formula.

@joelanford joelanford reopened this Aug 21, 2019
@mandymchu
Copy link

mandymchu commented Aug 21, 2019

@joelanford After uninstall and reinstall, now which go -a returns /usr/local/go/bin/go.
BTW, /usr/local/go for GOROOT was manually exported before adding api, otherwise the output complained runtime error: invalid memory address or nil pointer dereference.

@hasbro17
Copy link
Contributor

This might be a go modules related issue.

While I'm not getting the index out of range panic I do see the runtime error: invalid memory address or nil pointer dereference if I run the command inside $GOPATH/src with GO111MODULES=on:

$ operator-sdk version
operator-sdk version: v0.9.0-50-g4ca881a9, commit: 4ca881a92eb71b19d4689065ae9bf4dcf9b43331

$ operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
INFO[0000] Generating api version app.example.com/v1alpha1 for kind AppService.
INFO[0000] Created pkg/apis/app/group.go
INFO[0005] Created pkg/apis/app/v1alpha1/appservice_types.go
INFO[0005] Created pkg/apis/addtoscheme_app_v1alpha1.go
INFO[0005] Created pkg/apis/app/v1alpha1/register.go
INFO[0005] Created pkg/apis/app/v1alpha1/doc.go
INFO[0005] Created deploy/crds/app_v1alpha1_appservice_cr.yaml
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x18e98d5]

goroutine 1 [running]:
k8s.io/gengo/parser.(*Builder).AddDirRecursive(0xc0003a20a0, 0xc000542300, 0x32, 0x2, 0x2)
	pkg/mod/k8s.io/[email protected]/parser/parse.go:229 +0xb5
sigs.k8s.io/controller-tools/pkg/crd/generator.(*Generator).Do(0xc000729760, 0x0, 0x0)
	pkg/mod/sigs.k8s.io/[email protected]/pkg/crd/generator/generator.go:126 +0x3ac
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*CRD).CustomRender(0xc000268160, 0x2cff980, 0x4000ca0, 0x73f29d0, 0xc000268160, 0x1)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/crd.go:102 +0x27e
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doRender(0xc000729cf8, 0xc0000b2270, 0x2c, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000058211, 0x29, ...)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/scaffold.go:222 +0x16c
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).doFile(0xc000729cf8, 0x2c85720, 0xc000268160, 0x0, 0x0)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/scaffold.go:192 +0x230
github.com/operator-framework/operator-sdk/internal/pkg/scaffold.(*Scaffold).Execute(0xc000729cf8, 0xc000729c68, 0xc000729c98, 0x6, 0x6, 0x0, 0x0)
	/Users/haseeb/work/module-projects/operator-sdk/internal/pkg/scaffold/scaffold.go:157 +0x103
github.com/operator-framework/operator-sdk/cmd/operator-sdk/add.apiRun(0xc000570280, 0xc00000cc20, 0x0, 0x2, 0x0, 0x0)
	/Users/haseeb/work/module-projects/operator-sdk/cmd/operator-sdk/add/api.go:118 +0x542
github.com/spf13/cobra.(*Command).execute(0xc000570280, 0xc00000cbc0, 0x2, 0x2, 0xc000570280, 0xc00000cbc0)
	pkg/mod/github.com/spf13/[email protected]/command.go:762 +0x465
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000f1b80, 0x2c88c00, 0xc000321e00, 0x0)
	pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x2ec
github.com/spf13/cobra.(*Command).Execute(...)
	pkg/mod/github.com/spf13/[email protected]/command.go:800
main.main()
	/Users/haseeb/work/module-projects/operator-sdk/cmd/operator-sdk/main.go:85 +0x50f

With GO111MODULES=off inside $GOPATH/src or running the command outside of $GOPATH/src there is no issue.

Debugging this a bit more with the master branch to confirm.

@YanRyan
Copy link
Author

YanRyan commented Aug 22, 2019

brew install

I still have this problem, I suggest that do not use "brew install brew install operator-sdk . Use make install . I also try to reinstall go and operator-sdk, but it's not work. So I find a Centos 7.5 machine to install the operator-sdk then it could work.

@joelanford
Copy link
Member

@YanRyan @mandymchu Can you try uninstalling your brew-installed operator-sdk and go, and instead building from source as described here and see if you still have the problem?

My current hypothesis is that there's something intrinsic in the operator-sdk binary from it's original build environment that causes problems if it's used with a different go environment. It seems like I'm unable to reproduce the issue when I build from source and re-use the same Go installation to build and run operator-sdk.

@hasbro17
Copy link
Contributor

Update: I can't reproduce the above runtime error anymore.

$ operator-sdk version
operator-sdk version: v0.10.0, commit: ff80b17737a6a0aade663e4827e8af3ab5a21170

// Inside $GOPATH/src
$ pwd
/Users/haseeb/work/go-space/src/github.com/example-inc

$ GO111MODULE=on operator-sdk new app-operator
INFO[0000] Creating new Go operator 'app-operator'.
INFO[0000] Created go.mod
INFO[0000] Created tools.go
INFO[0000] Created cmd/manager/main.go
INFO[0000] Created build/Dockerfile
INFO[0000] Created build/bin/entrypoint
INFO[0000] Created build/bin/user_setup
INFO[0000] Created deploy/service_account.yaml
INFO[0000] Created deploy/role.yaml
INFO[0000] Created deploy/role_binding.yaml
INFO[0000] Created deploy/operator.yaml
INFO[0000] Created pkg/apis/apis.go
INFO[0000] Created pkg/controller/controller.go
INFO[0000] Created version/version.go
INFO[0000] Created .gitignore
INFO[0000] Validating project
go: finding github.com/operator-framework/operator-sdk master
INFO[0004] Project validation successful.
INFO[0004] Project creation complete.

// GO111MODULE=off inside $GOPATH now results in the correct error
$ cd app-operator/
$ GO111MODULE=off operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
FATA[0000] dependency manager "modules" requires working directory to be in $GOPATH/src and GO111MODULE=on, or outside of $GOPATH/src and GO111MODULE="on", "auto", or unset. More info: https://github.com/operator-framework/operator-sdk/blob/master/doc/user-guide.md#go-modules

$ GO111MODULE=on operator-sdk add api --api-version=app.example.com/v1alpha1 --kind=AppService
INFO[0000] Generating api version app.example.com/v1alpha1 for kind AppService.
INFO[0000] Created pkg/apis/app/group.go
INFO[0002] Created pkg/apis/app/v1alpha1/appservice_types.go
INFO[0002] Created pkg/apis/addtoscheme_app_v1alpha1.go
INFO[0002] Created pkg/apis/app/v1alpha1/register.go
INFO[0002] Created pkg/apis/app/v1alpha1/doc.go
INFO[0002] Created deploy/crds/app_v1alpha1_appservice_cr.yaml
INFO[0010] Created deploy/crds/app_v1alpha1_appservice_crd.yaml
INFO[0010] Running deepcopy code-generation for Custom Resource group versions: [app:[v1alpha1], ]
INFO[0018] Code-generation complete.
INFO[0018] Running OpenAPI code-generation for Custom Resource group versions: [app:[v1alpha1], ]
INFO[0034] Created deploy/crds/app_v1alpha1_appservice_crd.yaml
INFO[0034] Code-generation complete.
INFO[0034] API generation complete.

Same for the version that I initially tested out with operator-sdk version: v0.9.0-54-gabac23c8, commit: abac23c897b898e6fecfb2c02fe318843ae9347f.

Not entirely sure what I changed or how I managed to run add api inside $GOPATH/src with GO111MODULE=off before.

@mandymchu
Copy link

mandymchu commented Aug 22, 2019

@joelanford @hasbro17 I uninstalled brew-installed operator-sdk and installed it from Github release, also confirmed that /usr/local/Cellar/go was removed which means only one go (/usr/local/go) installed. However, they does not fix the issue...

BTW: it works on redhat, and no need to export GOROOT manually.

@jiwq
Copy link

jiwq commented Aug 26, 2019

@joelanford @hasbro17 In my macOS(installed go and operator-sdk by brew), I reproduce this issue. But when I uninstall operator-sdk and make install from source in master(abac23c), it works well. So I think maybe we need to release one new version for this. Any thoughts?
@YanRyan Can you try with this?

@joelanford
Copy link
Member

@jiwq @YanRyan @camilamacedo86 I think I've got this one finally figured out. See #1854 (comment)

@satishrao84
Copy link

satishrao84 commented Sep 30, 2019

I still get panic: runtime error: index out of range even after explicitly setting GOROOT.

bash-3.2$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/sanupin/Library/Caches/go-build"
GOENV="/Users/sanupin/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/sanupin/go-workspace"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/sanupin/go-workspace/src/couchbase-cluster-operator/go.mod"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sr/n5q9l_fn7yj8mx6rbfq8smbn72mpx6/T/go-build664640064=/tmp/go-build -gno-record-gcc-switches -fno-common"

bash-3.2$ GOROOT='/usr/local/go' operator-sdk add api --api-version=couchbase.com/v1 --kind=CouchbaseCluster
INFO[0000] Generating api version couchbase.com/v1 for kind CouchbaseCluster.
INFO[0000] Created pkg/apis/couchbase/group.go
panic: runtime error: index out of range

goroutine 119 [running]:
golang.org/x/tools/imports.(*moduleResolver).scan.func1(0xc0007bb950, 0x23, 0x4, 0xc0005a8f60, 0x42)
pkg/mod/golang.org/x/[email protected]/imports/mod.go:254 +0x9df
golang.org/x/tools/internal/gopathwalk.(*walker).walk(0xc0002e0540, 0xc0005a8f60, 0x52, 0x0, 0xc0005a8f60, 0x52)
pkg/mod/golang.org/x/[email protected]/internal/gopathwalk/walk.go:175 +0xf5
golang.org/x/tools/internal/fastwalk.(*walker).onDirEnt(0xc0006c0090, 0xc00072caa0, 0x42, 0xc000013820, 0xf, 0xc000000000, 0x0, 0x0)
pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:168 +0xbb
golang.org/x/tools/internal/fastwalk.readDir(0xc00072caa0, 0x42, 0xc00084de88, 0x0, 0x0)
pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk_unix.go:68 +0x212
golang.org/x/tools/internal/fastwalk.(*walker).walk(0xc0006c0090, 0xc00072caa0, 0x42, 0x1, 0x1, 0x0)
pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:195 +0x6a
golang.org/x/tools/internal/fastwalk.(*walker).doWork(0xc0006c0090, 0xc000862e80)
pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:134 +0x14d
created by golang.org/x/tools/internal/fastwalk.Walk
pkg/mod/golang.org/x/[email protected]/internal/fastwalk/fastwalk.go:81 +0x21d

Have reinstalled Go, reinstalled operator-sdk. Nothing works. Please help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/duplicate Indicates an issue is a duplicate of other open issue. triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

7 participants