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

Panic when running contextcheck #5480

Closed
6 of 7 tasks
palsivertsen opened this issue Feb 27, 2025 · 4 comments
Closed
6 of 7 tasks

Panic when running contextcheck #5480

palsivertsen opened this issue Feb 27, 2025 · 4 comments
Assignees
Labels
bug Something isn't working dependencies Relates to an upstream dependency

Comments

@palsivertsen
Copy link

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

How did you install golangci-lint?

AUR

Description of the problem

First off, apologies if this is an issue with the contextcheck and not golangci-lint.

I get the following panic when running golangci-lint with contextcheck:

ERRO [runner] Panic: contextcheck: package "main" (isInitialPkg: true, needAnalyzeSource: true): unreachable: goroutine 385 [running]:

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.64.5 built with go1.24.0 from 0a603e49 on 2025-02-13T21:19:55Z

Configuration

-no-config --disable-all --enable contextcheck

Go environment

$ go version && go env
go version go1.24.0 linux/amd64
AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/pal/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/pal/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1505087625=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/tmp/tmp.sSLzfc5dYn/go.mod'
GOMODCACHE='/home/pal/go/pkg/mod'
GONOPROXY='REDACTED'
GONOSUMDB='REDACTED'
GOOS='linux'
GOPATH='/home/pal/go'
GOPRIVATE='REDACTED'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/lib/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/pal/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/lib/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.24.0'
GOWORK=''
PKG_CONFIG='pkg-config'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v --no-config --disable-all --enable contextcheck main.go
INFO golangci-lint has version 1.64.5 built with go1.24.0 from 0a603e49 on 2025-02-13T21:19:55Z 
INFO [goenv] Read go env for 3.442715ms: map[string]string{"GOCACHE":"/home/pal/.cache/go-build", "GOROOT":"/usr/lib/go"} 
INFO [lintersdb] Active 1 linters: [contextcheck] 
INFO [loader] Go packages loading at mode 8767 (name|compiled_files|files|types_sizes|deps|exports_file|imports) took 60.596234ms 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 112.958µs 
INFO [linters_context/goanalysis] analyzers took 178.142403ms with top 10 stages: buildssa: 171.928575ms, contextcheck: 6.209283ms, typecheck: 4.545µs 
ERRO [runner] Panic: contextcheck: package "main" (isInitialPkg: true, needAnalyzeSource: true): unreachable: goroutine 379 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x5e
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe.func1()
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:50 +0x257
panic({0x123e7a0?, 0x172a0b0?})
	runtime/panic.go:787 +0x132
go/types.(*comparer).identical(0xc00193d71c, {0x173ad88?, 0x2154420?}, {0x17397b8?, 0xc0018a85b0?}, 0x0)
	go/types/predicates.go:499 +0x998
go/types.(*comparer).identical(0xc00197171c, {0x17398d0?, 0x2154410?}, {0x17398d0?, 0xc00252c820?}, 0x0)
	go/types/predicates.go:313 +0x57f
go/types.Identical(...)
	go/types/api_predicates.go:90
github.com/kkHAIKE/contextcheck.(*runner).isCtxType(0xc001b2c660, {0x17398d0, 0x2154410})
	github.com/kkHAIKE/contextcheck@v1.1.5/contextcheck.go:730 +0x79
github.com/kkHAIKE/contextcheck.(*runner).getCallInstrCtxType(0xc001b2c660, {0x72ed4089eeb0, 0xc001b12400})
	github.com/kkHAIKE/contextcheck@v1.1.5/contextcheck.go:669 +0xfc
github.com/kkHAIKE/contextcheck.(*runner).getCtxType(0xc001b2c660?, {0x1746578?, 0xc001b12400?})
	github.com/kkHAIKE/contextcheck@v1.1.5/contextcheck.go:643 +0xc5
github.com/kkHAIKE/contextcheck.(*runner).checkFuncWithoutCtx(0xc001b2c660, 0xc001b26e00, 0xc00193db20)
	github.com/kkHAIKE/contextcheck@v1.1.5/contextcheck.go:572 +0x13b
github.com/kkHAIKE/contextcheck.(*runner).run(0xc001b2c660, 0xc0025b4620)
	github.com/kkHAIKE/contextcheck@v1.1.5/contextcheck.go:173 +0x4c5
github.com/kkHAIKE/contextcheck.NewRun.func1(0xc0025b4620)
	github.com/kkHAIKE/contextcheck@v1.1.5/contextcheck.go:131 +0xf9
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze.func3(...)
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_checker.go:182
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyze(0xc001f40008)
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_checker.go:208 +0xb62
github.com/golangci/golangci-lint/pkg/timeutils.(*Stopwatch).TrackStage(0xc0019ce7d0, {0x14af4e6, 0xc}, 0xc000f26f48)
	github.com/golangci/golangci-lint/pkg/timeutils/stopwatch.go:111 +0x44
github.com/golangci/golangci-lint/pkg/goanalysis.(*action).analyzeSafe(0xc00005c9c0?)
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_action.go:54 +0x71
github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze.func2(0xc001f40008)
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:83 +0xa5
created by github.com/golangci/golangci-lint/pkg/goanalysis.(*loadingPackage).analyze in goroutine 202
	github.com/golangci/golangci-lint/pkg/goanalysis/runner_loadingpackage.go:78 +0x1e9 
WARN [runner] Can't run linter goanalysis_metalinter: goanalysis_metalinter: contextcheck: package "main" (isInitialPkg: true, needAnalyzeSource: true): unreachable 
INFO [runner] processing took 2.422µs with stages: max_same_issues: 309ns, exclusion_paths: 203ns, path_absoluter: 186ns, skip_dirs: 178ns, exclusion_rules: 162ns, nolint_filter: 161ns, skip_files: 151ns, generated_file_filter: 100ns, sort_results: 96ns, diff: 96ns, max_per_file_from_linter: 93ns, filename_unadjuster: 93ns, source_code: 91ns, path_relativity: 88ns, max_from_linter: 81ns, path_prettifier: 61ns, cgo: 43ns, fixer: 42ns, invalid_issue: 41ns, path_shortener: 40ns, uniq_by_line: 36ns, severity-rules: 36ns, identifier_marker: 35ns 
INFO [runner] linters took 428.036783ms with stages: goanalysis_metalinter: 428.000257ms 
ERRO Running error: can't run linter goanalysis_metalinter
goanalysis_metalinter: contextcheck: package "main" (isInitialPkg: true, needAnalyzeSource: true): unreachable 
INFO Memory: 6 samples, avg is 88.0MB, max is 137.7MB 
INFO Execution took 492.711172ms

A minimal reproducible example or link to a public repository

package main

import (
	"context"
	"iter"
)

func main() {
	var iter iter.Seq[any]
	for range iter {
		_, cancel := context.WithCancel(context.Background())
		defer cancel()
	}
}

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@palsivertsen palsivertsen added the bug Something isn't working label Feb 27, 2025
Copy link

boring-cyborg bot commented Feb 27, 2025

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

@ldez ldez self-assigned this Feb 27, 2025
@ldez ldez added the dependencies Relates to an upstream dependency label Feb 27, 2025
@ldez
Copy link
Member

ldez commented Feb 27, 2025

Hello,

this is contextcheck error, can you open an issue on the repo https://github.com/kkHAIKE/contextcheck?

@ldez
Copy link
Member

ldez commented Feb 27, 2025

Your example is panicking by itself:

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

goroutine 1 [running]:
main.main()
        /home/ldez/sources/golangci/sandbox/foo.go:10 +0x8d
exit status 2

But an working example also panic:

package main

import (
	"context"
	"slices"
)

func main() {
	seq := slices.Values([]any{"a"})
	for range seq {
		_, cancel := context.WithCancel(context.Background())
		defer cancel()
	}
}

@ldez
Copy link
Member

ldez commented Mar 1, 2025

Fixed by #5482

@ldez ldez closed this as completed Mar 1, 2025
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

No branches or pull requests

2 participants