samba-in-kubernetes / samba-operator

An operator for a Samba as a service on PVCs in kubernetes
Apache License 2.0
117 stars 24 forks source link

Panic seen with golangci-lint and gosec during `make check` #344

Closed anoopcs9 closed 2 months ago

anoopcs9 commented 2 months ago

/home/runner/work/samba-operator/samba-operator/.bin/golangci-lint -c .golangci.yaml run ./... level=error msg="[runner] Panic: atomicalign: package \"v1alpha1\" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference: goroutine 11625 [running]:\nruntime/debug.Stack()\n\t/opt/hostedtoolcache/go/1.22.6/x64/src/runtime/debug/stack.go:24 +0x5e\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(action).analyzeSafe.func1()\n\t/home/runner/go/pkg/mod/github.com/golangci/golangci-lint@v1.53.3/pkg/golinters/goanalysis/runner_action.go:109 +0x277\npanic({0x1635220?, 0x2216370?})\n\t/opt/hostedtoolcache/go/1.22.6/x64/src/runtime/panic.go:770 +0x132\ngo/types.(StdSizes).Sizeof(0x0, {0x1a233e0, 0x222e080})\n\t/opt/hostedtoolcache/go/1.22.6/x64/src/go/types/sizes.go:228 +0x30f\ngolang.org/x/tools/go/analysis/passes/atomicalign.run(0xc035d8e270)\n\t/home/runner/go/pkg/mod/golang.org/x/tools@v0.9.3/go/analysis/passes/atomicalign/atomicalign.go:34 +0x52\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(action).analyze(0xc002252400)\n\t/home/runner/go/pkg/mod/github.com/golangci/golangci-lint@v1.53.3/pkg/golinters/goanalysis/runner_action.go:195 +0x99a\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(action).analyzeSafe.func2()\n\t/home/runner/go/pkg/mod/github.com/golangci/golangci-lint@v1.53.3/pkg/golinters/goanalysis/runner_action.go:113 +0x17\ngithub.com/golangci/golangci-lint/pkg/timeutils.(Stopwatch).TrackStage(0xc001180b40, {0x17d1a61, 0xb}, 0xc0026d2f48)\n\t/home/runner/go/pkg/mod/github.com/golangci/golangci-lint@v1.53.3/pkg/timeutils/stopwatch.go:111 +0x44\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(action).analyzeSafe(0xc001630600?)\n\t/home/runner/go/pkg/mod/github.com/golangci/golangci-lint@v1.53.3/pkg/golinters/goanalysis/runner_action.go:112 +0x7a\ngithub.com/golangci/golangci-lint/pkg/golinters/goanalysis.(loadingPackage).analyze.func2(0xc002252400)\n\t/home/runner/go/pkg/mod/github.com/golangci/golangci-lint@v1.53.3/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0xa8\ncreated by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(loadingPackage).analyze in goroutine 165\n\t/home/runner/go/pkg/mod/github.com/golangci/golangci-lint@v1.53.3/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x205\n" level=warning msg="[runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: atomicalign: package \"v1alpha1\" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference" level=error msg="Running error: 1 error occurred:\n\t* can't run linter goanalysis_metalinter: goanalysis_metalinter: atomicalign: package \"v1alpha1\" (isInitialPkg: true, needAnalyzeSource: true): runtime error: invalid memory address or nil pointer dereference\n\n"

https://github.com/samba-in-kubernetes/samba-operator/actions/runs/10490329713/job/29093282639

anoopcs9 commented 2 months ago

Last time we ran make check with go1.21 and it was successful. But go1.22 seems to be unhappy with the current golangci-lint version. Adding some reference issues:

From my understanding root cause might be https://github.com/golang/go/issues/31163. To be frank I don't know why this has become a problem with go1.22 🤷🏻‍♂️ .

anoopcs9 commented 2 months ago

Another similar panic with current gosec version:

panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x61034f]

goroutine 112 [running]: go/types.(Checker).handleBailout(0xc0011ee000, 0xc0011e9c60) /usr/lib/golang/src/go/types/check.go:367 +0x88 panic({0x777ac0?, 0xae6ed0?}) /usr/lib/golang/src/runtime/panic.go:770 +0x132 go/types.(StdSizes).Sizeof(0x0, {0x875570, 0xaeb720}) /usr/lib/golang/src/go/types/sizes.go:228 +0x30f go/types.(Config).sizeof(...) /usr/lib/golang/src/go/types/sizes.go:333 go/types.representableConst.func1({0x875570?, 0xaeb720?}) /usr/lib/golang/src/go/types/const.go:76 +0x9e go/types.representableConst({0x876988, 0xc00128aa18}, 0xc0011ee000, 0xaeb720, 0xc0011e93d0) /usr/lib/golang/src/go/types/const.go:92 +0x192 go/types.(Checker).representation(0xc0011ee000, 0xc000dc7100, 0xaeb720) /usr/lib/golang/src/go/types/const.go:256 +0x65 go/types.(Checker).implicitTypeAndValue(0xc0011ee000, 0xc000dc7100, {0x875570, 0xaeb720}) /usr/lib/golang/src/go/types/expr.go:375 +0x2d7 go/types.(Checker).assignment(0xc0011ee000, 0xc000dc7100, {0x875570, 0xaeb720}, {0x7dbf19, 0x14}) /usr/lib/golang/src/go/types/assignments.go:52 +0x2e5 go/types.(Checker).initConst(0xc0011ee000, 0xc000427260, 0xc000dc7100) /usr/lib/golang/src/go/types/assignments.go:126 +0x2c5 go/types.(Checker).constDecl(0xc0011ee000, 0xc000427260, {0x875a68, 0xc000f74460}, {0x875ac8, 0xc000f74480}, 0x0) /usr/lib/golang/src/go/types/decl.go:490 +0x311 go/types.(Checker).objDecl(0xc0011ee000, {0x87a418, 0xc000427260}, 0x0) /usr/lib/golang/src/go/types/decl.go:191 +0xa49 go/types.(Checker).packageObjects(0xc0011ee000) /usr/lib/golang/src/go/types/resolver.go:693 +0x4dd go/types.(Checker).checkFiles(0xc0011ee000, {0xc00101c640, 0x2, 0x2}) /usr/lib/golang/src/go/types/check.go:408 +0x1a5 go/types.(Checker).Files(...) /usr/lib/golang/src/go/types/check.go:372 golang.org/x/tools/go/packages.(loader).loadPackage(0xc00105c0e0, 0xc000399f00) /home/anoopcs/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:1001 +0x76f golang.org/x/tools/go/packages.(loader).loadRecursive.func1() /home/anoopcs/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:838 +0x1a9 sync.(Once).doSlow(0x0?, 0x0?) /usr/lib/golang/src/sync/once.go:74 +0xc2 sync.(Once).Do(...) /usr/lib/golang/src/sync/once.go:65 golang.org/x/tools/go/packages.(loader).loadRecursive(0x0?, 0x0?) /home/anoopcs/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:826 +0x4a golang.org/x/tools/go/packages.(loader).refine.func2(0x0?) /home/anoopcs/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:761 +0x26 created by golang.org/x/tools/go/packages.(*loader).refine in goroutine 51 /home/anoopcs/go/pkg/mod/golang.org/x/tools@v0.1.12/go/packages/packages.go:760 +0xc9a