Golangci-lint: Panic on go1.11 environment

Created on 10 Jul 2018  路  16Comments  路  Source: golangci/golangci-lint

Hi, I'm experiencing a strange behaviour with latest (1.9.1) version of golangci-lint.

I'm running it like so:

      if [ -n "${CI_TARGET_BRANCH}" ]; then
        golangci-lint run \
          --enable-all \
          --exclude "File is not goimports-ed" \
          --exclude "File is not gofmt-ed with -s" \
          --new-from-rev ${CI_TARGET_BRANCH}
      else
        golangci-lint run \
          --enable-all \
          --exclude "File is not goimports-ed" \
          --exclude "File is not gofmt-ed with -s" \
          --new
      fi

When I run it on my OS X dev machine, it works ok.

But when I run the same version of linter with same settings against same code on CI/CD environment (Ubuntu-based container), it always crashes with one of the following errors (I'm using this linter for many projects in my org and it crashes for all of them):

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

goroutine 1668 [running]:
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.(*fnVisitor).Visit(0xc4527b7ce0, 0xd35500, 0xc42ed7d440, 0x40e5e8, 0xb3f5a0)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:837 +0x393
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.(*globalVisitor).Visit(0xc4527b7cc0, 0xd35500, 0xc42ed7d440, 0xd31fe0, 0xc4527b7cc0)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:820 +0xd1
go/ast.Walk(0xd31fe0, 0xc4527b7cc0, 0xd35500, 0xc42ed7d440)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:52 +0x66
go/ast.walkDeclList(0xd31fe0, 0xc4527b7cc0, 0xc4374e4f00, 0x8, 0x8)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:38 +0x81
go/ast.Walk(0xd31fe0, 0xc4527b7cc0, 0xd35480, 0xc4374e5100)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:353 +0x2650
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.NodeFns.func1(0xc44305de20, 0xc452f86f00, 0xc452a93ef0)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:787 +0x74
created by github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.NodeFns
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:784 +0xe7
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x9cd676]

goroutine 807 [running]:
github.com/golangci/golangci-lint/vendor/golang.org/x/tools/go/ssa.(*Package).Func(...)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/golang.org/x/tools/go/ssa/ssa.go:1532
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.(*globalVisitor).Visit(0xc4256c7760, 0xd35100, 0xc42034e040, 0x0, 0x0)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:816 +0x196
go/ast.Walk(0xd31fe0, 0xc4256c7760, 0xd35100, 0xc42034e040)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:52 +0x66
go/ast.walkExprList(0xd31fe0, 0xc4256c7760, 0xc42033c070, 0x1, 0x1)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:26 +0x81
go/ast.Walk(0xd31fe0, 0xc4256c7760, 0xd35c40, 0xc42086e0a0)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:308 +0x564
go/ast.Walk(0xd31fe0, 0xc4256c7760, 0xd355c0, 0xc42034e300)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:331 +0xf2f
go/ast.walkDeclList(0xd31fe0, 0xc4256c7760, 0xc42034e500, 0x3, 0x4)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:38 +0x81
go/ast.Walk(0xd31fe0, 0xc4256c7760, 0xd35480, 0xc42002e180)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:353 +0x2650
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.NodeFns.func1(0xc4256c7700, 0xc4280efaa0, 0xc426af7320)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:787 +0x74
created by github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.NodeFns
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:784 +0xe7
bug

Most helpful comment

For alpine container, adding apk add build-base solved issue

All 16 comments

I can reproduce it in docker container golang:1.10-alpine.

Can't find the root of problem, but it looks like this problem with megacheck was already fixed, because after dep ensure this panic is gone

Are you looking at a making a 1.9.2 release to address this? Is there a work-around that can be applied for users of the golangci-lint binary in the meantime (other than disabling megacheck)?

~Is this really related to megacheck? I get the same error for one of our repos, no matter which subset of linters is enabled. For our other repos there is no issue at all, also not with megacheck enabled.~ This was a configuration error on my end. Apparently, if you don't explicitly disable megacheck it will be enabled.

Facing the same issue since I switched to go1.11beta2. Maybe it's related ?

Same issue here 1.9 doesn't have this issue, but 1.11 crashes every time.

Any plans to cut a 1.9.2? Or should users build their own for the time being

hi!
sorry for the late response.
It looks like cgo issue: you can check it by running with env var GL_DEBUG=linters_output.
If it outputs

exec: "gcc": executable file not found in $PATH
cgo failed: [go tool cgo -objdir /tmp/os_user_C215219741 -- -I /tmp/os_user_C215219741 cgo_lookup_unix.go getgrouplist_unix.go listgroups_unix.go]: exit statu
s 1
/usr/local/go/src/os/user/lookup.go:58:9: undeclared name: listGroups
/usr/local/go/src/os/user/lookup.go:11:41: undeclared name: current
/usr/local/go/src/os/user/lookup.go:32:9: undeclared name: lookupUser
/usr/local/go/src/os/user/lookup.go:41:9: undeclared name: lookupUserId
/usr/local/go/src/os/user/lookup.go:47:9: undeclared name: lookupGroup
/usr/local/go/src/os/user/lookup.go:53:9: undeclared name: lookupGroupId

try to install gcc or run with CGO_ENABLED=0.

Did it start after a specific golangci-lint release?

I've found that similar panic is thrown when golangci-lint runs under golang:alpine Docker image, and doesn't throw when it runs on golang (without Alpine) Docker image. Maybe it will be useful for someone.

@jirfag Here is the Debug disabling CGO and gcc didn't make a difference

It looks like the issue is already known/solved https://github.com/golangci/golangci-lint/issues/157#issuecomment-404520516 possibly

/home/travis/.gimme/versions/go/src/internal/cpu/cpu_x86.go:9:7: CacheLineSize redeclared in this block
/home/travis/.gimme/versions/go/src/internal/cpu/cpu_wasm.go:7:7:   other declaration of CacheLineSize
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:8:2: ArchFamily redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:8:2:     other declaration of ArchFamily
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:9:2: BigEndian redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:9:2:     other declaration of BigEndian
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:10:2: CacheLineSize redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:10:2:    other declaration of CacheLineSize
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:11:2: DefaultPhysPageSize redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:11:2:    other declaration of DefaultPhysPageSize
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:12:2: PCQuantum redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:12:2:    other declaration of PCQuantum
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:13:2: Int64Align redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:13:2:    other declaration of Int64Align
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:14:2: HugePageSize redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:14:2:    other declaration of HugePageSize
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:15:2: MinFrameSize redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:15:2:    other declaration of MinFrameSize
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_wasm.go:18:6: Uintreg redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/sys/arch_amd64.go:18:6:    other declaration of Uintreg
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:14:6: Load redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:13:6:  other declaration of Load
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:20:6: Loadp redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:19:6:  other declaration of Loadp
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:26:6: Load64 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:25:6:  other declaration of Load64
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:32:6: Xadd redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:30:6:  other declaration of Xadd
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:40:6: Xadd64 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:33:6:  other declaration of Xadd64
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:48:6: Xadduintptr redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:36:6:  other declaration of Xadduintptr
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:56:6: Xchg redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:39:6:  other declaration of Xchg
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:64:6: Xchg64 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:42:6:  other declaration of Xchg64
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:72:6: Xchguintptr redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:45:6:  other declaration of Xchguintptr
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:80:6: And8 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:48:6:  other declaration of And8
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:86:6: Or8 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:51:6:  other declaration of Or8
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:94:6: Cas64 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:104:6: Store redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:59:6:  other declaration of Store
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:110:6: Store64 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:62:6:  other declaration of Store64
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:116:6: StorepNoWB redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_amd64x.go:68:6:  other declaration of StorepNoWB
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:12:6: Cas redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:122:6:   other declaration of Cas
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:15:6: Casp1 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:132:6:   other declaration of Casp1
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:18:6: Casuintptr redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:142:6:   other declaration of Casuintptr
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:21:6: Storeuintptr redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:152:6:   other declaration of Storeuintptr
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:24:6: Loaduintptr redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:158:6:   other declaration of Loaduintptr
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:27:6: Loaduint redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:164:6:   other declaration of Loaduint
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:32:6: Loadint64 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:170:6:   other declaration of Loadint64
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/stubs.go:35:6: Xaddint64 redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/internal/atomic/atomic_wasm.go:176:6:   other declaration of Xaddint64
/home/travis/.gimme/versions/go/src/runtime/sys_x86.go:16:6: gostartcall redeclared in this block
/home/travis/.gimme/versions/go/src/runtime/sys_wasm.go:31:6:   other declaration of gostartcall
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x9cdae3]
goroutine 1019 [running]:
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.(*fnVisitor).Visit(0xc42f6f91a0, 0xd35500, 0xc421405410, 0x40e5e8, 0xb3f5a0)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:837 +0x393
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.(*globalVisitor).Visit(0xc42f6f8d20, 0xd35500, 0xc421405410, 0xd31fe0, 0xc42f6f8d20)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:820 +0xd1
go/ast.Walk(0xd31fe0, 0xc42f6f8d20, 0xd35500, 0xc421405410)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:52 +0x66
go/ast.walkDeclList(0xd31fe0, 0xc42f6f8d20, 0xc4211e5e00, 0x11, 0x20)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:38 +0x81
go/ast.Walk(0xd31fe0, 0xc42f6f8d20, 0xd35480, 0xc42142a480)
    /home/travis/.gimme/versions/go1.10.3.linux.amd64/src/go/ast/walk.go:353 +0x2650
github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.NodeFns.func1(0xc429a443a0, 0xc42c539140, 0xc4277a7980)
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:787 +0x74
created by github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint.NodeFns
    /home/travis/gopath/src/github.com/golangci/golangci-lint/vendor/honnef.co/go/tools/lint/lint.go:784 +0xe7

@fat0troll it's because golang image has gcc installed

@nikitabokovoy what do you mean by dep ensure? golangci-lint already comes with vendor dir, also dep ensure on our repo doesn't update linters.

@Sean-Der you have the similar to https://github.com/golangci/golangci-lint/issues/156#issuecomment-407904118 issue: hidden compilation errors aren't reported (bug) by golangci-lint. Megacheck can't work if there are compilation errors.
But your errors look strange, is it go1.11beta2?

@jirfag dep ensure loads current master branch of honnef.co/go/tools into vendor

[[constraint]]
  branch = "master"
  name = "honnef.co/go/tools"

Steps that i take:
1) clone this repo inside of alpine container
2) go install in cmd/golangci-lint
3) run golangci-lint on my project and got panic
4) dep ensure in golangci-lint repo
5) go install
6) run golangci-lint and and everything OK

@nikitabokovoy thank you, I will check it

@nikitabokovoy is it golang:1.10-alpine container? I did it by your steps, it didn't help. And it shouldn't: dep ensure doesn't update dependencies without -update option. Also, it can't update megacheck even with -update because we use a fork of megacheck.

to sum up:

  1. panic occurred when compilation failed in system (e.g. net) packages, I fixed it: now it stops linting for linters (megacheck, etc) that can't process a program with compilation errors.
  2. system packages aren't compiling in two cases:

    • go1.11 env when golangci-lint build by go1.10 because of lack of _wasm.go files support in go < 1.11. To fix it you should compile golangci-lint by go1.11. But don't do that: go1.11 isn't stable yet and has critical bugs like this, so golangci-lint won't work properly.

    • no gcc installed (e.g. alpine container)

For alpine container, adding apk add build-base solved issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moolibdensplk picture moolibdensplk  路  4Comments

simonpasquier picture simonpasquier  路  4Comments

anuaimi picture anuaimi  路  4Comments

ferhatelmas picture ferhatelmas  路  4Comments

rhcarvalho picture rhcarvalho  路  4Comments