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

linter crashes with panic #1973

Closed
2 of 4 tasks
gucio321 opened this issue May 11, 2021 · 15 comments · Fixed by #1975
Closed
2 of 4 tasks

linter crashes with panic #1973

gucio321 opened this issue May 11, 2021 · 15 comments · Fixed by #1975
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@gucio321
Copy link

gucio321 commented May 11, 2021

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)
  • Yes, I've searched similar issues on GitHub and didn't find any.
Description of the problem

linter crashes on OpenDiablo2 project.
here is a workflow run, which reproduces this behavior

Version of golangci-lint
$ golangci-lint --version
golangci-lint has version 1.40.0 built from 5c6adb63 on 2021-05-10T10:45:21Z
Config file
$ cat .golangci.yml
---
linters-settings:
  dupl:
    threshold: 100
  funlen:
    lines: 100
    statements: 50
  goconst:
    min-len: 2
    min-occurrences: 2
  gocritic:
    enabled-tags:
      - diagnostic
      - experimental
      - opinionated
      - performance
      - style
    disabled-checks:
  gocyclo:
    min-complexity: 15
  gofmt:
    simplify: true
  goimports:
    local-prefixes: github.com/OpenDiablo2/OpenDiablo2
  golint:
    min-confidence: 0.8
  govet:
    enable-all: true
    check-shadowing: true
    disable:
      # While struct sizes could be smaller if fields aligned properly, that also leads
      # to possibly non-intuitive layout of struct fields (harder to read). Disable
      # `fieldalignment` check here until we evaluate if it is worthwhile.
      - fieldalignment
  lll:
    line-length: 140
  misspell:
    locale: US

linters:
  disable-all: true
  enable:
    - bodyclose
    - deadcode
    - depguard
    - dogsled
    - dupl
    - errcheck
    - funlen
    - gochecknoglobals
    - gochecknoinits
    - gocognit
    - goconst
    - gocritic
    - gocyclo
    - godox
    - gofmt
    - goimports
    - golint
    - gomnd
    - goprintffuncname
    - gosec
    - gosimple
    - govet
    - ineffassign
    - lll
    - misspell
    - nakedret
    - prealloc
    - rowserrcheck
    - staticcheck
    - structcheck
    - stylecheck
    - typecheck
    - unconvert
    - unparam
    - unused
    - varcheck
    - whitespace
    - wsl

run:
  timeout: 5m
  tests: true
  skip-dirs:
    - .github
    - build
    - web

issues:
  exclude-rules:
    - linters:
        - funlen
      # Disable 'funlen' linter for test functions.
      # It's common for table-driven tests to be more than 60 characters long
      source: "^func Test"
  max-issues-per-linter: 0
  max-same-issues: 0
  exclude-use-default: false
Go environment
$ go version && go env
go version go1.16.4 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOENV="/home/user/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/user/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/user/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3225948580=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v ./...
INFO [config_reader] Config search paths: [./ /home/mszeptuch/git/d2/me/OpenDiablo2 /home/mszeptuch/git/d2/me /home/mszeptuch/git/d2 /home/mszeptuch/git /home/mszeptuch /home /] 
INFO [config_reader] Used config file .golangci.yml 
INFO [lintersdb] Active 38 linters: [bodyclose deadcode depguard dogsled dupl errcheck funlen gochecknoglobals gochecknoinits gocognit goconst gocritic gocyclo godox gofmt goimports golint gomnd goprintffuncname gosec gosimple govet ineffassign lll misspell nakedret prealloc rowserrcheck staticcheck structcheck stylecheck typecheck unconvert unparam unused varcheck whitespace wsl] 
INFO [loader] Go packages loading at mode 575 (exports_file|files|imports|name|compiled_files|deps|types_sizes) took 454.737027ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 163.235443ms 
INFO [linters context/goanalysis] analyzers took 1m25.799685893s with top 10 stages: the_only_name: 4.987980064s, buildir: 4.764309399s, buildssa: 4.169827884s, gocritic: 4.089240111s, dupl: 3.977163207s, gosec: 3.601953723s, directives: 2.657086921s, whitespace: 2.580385854s, gocyclo: 2.355753677s, goimports: 2.350630905s 
WARN [linters context] Panic: bodyclose: package "d2app" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildssa.SSA: goroutine 10588 [running]:
runtime/debug.Stack(0x11f2447, 0x3c, 0xc0030fe9c8)
	runtime/debug/stack.go:24 +0x9f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc001a938c0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x1be
panic(0x1000a00, 0xc00b7c7920)
	runtime/panic.go:965 +0x1b9
github.com/timakin/bodyclose/passes/bodyclose.runner.run(0xc00a7b5d40, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc00a7b5d40, 0x0, ...)
	github.com/timakin/[email protected]/passes/bodyclose/bodyclose.go:45 +0x837
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc001a938c0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x9f2
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x2a
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc002e55770, 0x1159d21, 0x9, 0xc0046bef70)
	github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x4d
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc001a938c0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x91
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc009cf8df0, 0xc001a938c0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0x65
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x316 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: bodyclose: package "d2app" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildssa.SSA 
INFO [runner] processing took 3.476µs with stages: max_same_issues: 675ns, skip_dirs: 425ns, nolint: 317ns, cgo: 278ns, max_from_linter: 242ns, autogenerated_exclude: 212ns, uniq_by_line: 162ns, identifier_marker: 161ns, filename_unadjuster: 151ns, path_prettifier: 133ns, diff: 118ns, skip_files: 116ns, exclude: 68ns, path_shortener: 65ns, max_per_file_from_linter: 62ns, source_code: 62ns, severity-rules: 59ns, sort_results: 59ns, exclude-rules: 56ns, path_prefixer: 55ns 
INFO [runner] linters took 3.753465733s with stages: goanalysis_metalinter: 3.753419759s 
INFO File cache stats: 188 entries of total size 919.5KiB 
INFO Memory: 44 samples, avg is 237.9MB, max is 344.7MB 
INFO Execution took 4.378323222s   
Code example or link to a public repository

https://github.com/OpenDiablo2/OpenDiablo2

@gucio321 gucio321 added the bug Something isn't working label May 11, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented May 11, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented May 11, 2021

Hello,

The problem seems related to govet, as a workaround you can disable it.
I will investigate.

@ldez

This comment has been minimized.

@ldez ldez added the dependencies Relates to an upstream dependency label May 11, 2021
@ashanbrown
Copy link
Contributor

ashanbrown commented May 11, 2021

I've also seen some other panics that seem to be fixed by not running gotvet. This one doesn't appear to be related to nilness (although removing that fixed a different panic):

WARN [linters context] Panic: unusedwrite: package "main" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildssa.SSA: goroutine 20325 [running]:
runtime/debug.Stack(0x1df377c, 0x3c, 0xc003307af8)
	runtime/debug/stack.go:24 +0x9f
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func1(0xc00305bcd0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:101 +0x1be
panic(0x1c014e0, 0xc03eec8990)
	runtime/panic.go:965 +0x1b9
golang.org/x/tools/go/analysis/passes/unusedwrite.run(0xc0234131e0, 0x356c6d1c1, 0x26b3120, 0xc0136ed9b8, 0x2)
	golang.org/x/[email protected]/go/analysis/passes/unusedwrite/unusedwrite.go:74 +0x1c5
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyze(0xc00305bcd0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:187 +0x9f2
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe.func2()
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:105 +0x2a
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc00131f5e0, 0x1d91c5a, 0xb, 0xc003625f70)
	github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x4d
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*action).analyzeSafe(0xc00305bcd0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_action.go:104 +0x91
github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze.func2(0xc06efe3f00, 0xc00305bcd0)
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:80 +0x65
created by github.com/golangci/golangci-lint/pkg/golinters/goanalysis.(*loadingPackage).analyze
	github.com/golangci/golangci-lint/pkg/golinters/goanalysis/runner_loadingpackage.go:75 +0x316
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: unusedwrite: package "main" (isInitialPkg: true, needAnalyzeSource: true): interface conversion: interface {} is nil, not *buildssa.SSA

@ashanbrown

This comment has been minimized.

@ldez
Copy link
Member

ldez commented May 11, 2021

It's related to the same problem as nilness, the important information is interface conversion: interface {} is nil, not *buildssa.SSA:

2 "passes" are affected by this problem: nilness and unusedwrite

FYI I know the root cause of all those panics.

@ldez

This comment has been minimized.

@ldez
Copy link
Member

ldez commented May 12, 2021

The root cause is sigchanyzer but I'm still trying to understand why.

It only happens when the sigchanyzer reports a problem.

so the workaround:

  govet:
    enable-all: true
    disable:
      - sigchanyzer

@ashanbrown

This comment has been minimized.

@ldez

This comment has been minimized.

@ashanbrown

This comment has been minimized.

@ldez

This comment has been minimized.

@ldez
Copy link
Member

ldez commented May 12, 2021

Back to the main topic, the problem is in sigchanyzer, it's related to the following lines:
https://github.com/golang/tools/blob/be4aaae4cf865bd1e65ae3a22df28c1f47b6ccfd/go/analysis/passes/sigchanyzer/sigchanyzer.go#L62-L65

I think it's because it alters the AST.

@ldez
Copy link
Member

ldez commented May 12, 2021

I will open an issue and a PR on https://github.com/golang/tools.

A minimal reproducible example:

main.go
package main

import (
	"os"
	"os/signal"
	"syscall"
)

func main() {
	c := make(chan os.Signal)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)

	go func() {
		<-c
	}()
}
.golangci.yml
linters-settings:
  govet:
    disable-all: true
    enable:
      - nilness
      - sigchanyzer

linters:
  disable-all: true
  enable:
    - govet

@gucio321
Copy link
Author

gucio321 commented May 13, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Relates to an upstream dependency
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants