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 using rcrowley/go-metrics on Windows #1442

Closed
NathanBaulch opened this issue Aug 26, 2023 · 5 comments
Closed

Panic when using rcrowley/go-metrics on Windows #1442

NathanBaulch opened this issue Aug 26, 2023 · 5 comments
Labels

Comments

@NathanBaulch
Copy link

I'm new to staticcheck and one of my projects causes a panic.

> staticcheck .

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0x95abea]

goroutine 217 [running]:
go/types.(*StdSizes).Sizeof(0x0, {0xd5ea48?, 0x100bf40})
        go/types/sizes.go:228 +0x2ea
honnef.co/go/tools/staticcheck.checkAtomicAlignmentImpl(0xc000074780)
        honnef.co/go/tools@v0.4.5/staticcheck/lint.go:773 +0x65
honnef.co/go/tools/staticcheck.checkCalls.func1(0xc000234ce8?, {0xd66af0?, 0xc0000da4d0}, 0xc0004a8140)
        honnef.co/go/tools@v0.4.5/staticcheck/lint.go:3293 +0x32d
honnef.co/go/tools/staticcheck.eachCall(0xc0002ce780, 0xc000234d38)
        honnef.co/go/tools@v0.4.5/staticcheck/lint.go:2662 +0x12b
honnef.co/go/tools/staticcheck.checkCalls(0xc000234d78?, 0x80da8f?)
        honnef.co/go/tools@v0.4.5/staticcheck/lint.go:3334 +0x95
honnef.co/go/tools/staticcheck.init.makeCallCheckerAnalyzer.callChecker.func42(0xbf1ca0?)
        honnef.co/go/tools@v0.4.5/staticcheck/lint.go:3261 +0x17
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc000088c60, {0xd621c8?, 0xc00032ebe0})
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:992 +0x71e
honnef.co/go/tools/lintcmd/runner.genericHandle({0xd621c8?, 0xc00032ebe0}, {0xd621c8?, 0xc0000965a0?}, 0xc14880?, 0x0, 0xc000235300)
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:817 +0x113
honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers(0xc0000f5ae0, 0xc00024d0e0, 0xc000074230)
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:1065 +0x716
honnef.co/go/tools/lintcmd/runner.(*subrunner).doUncached(0x0?, 0xc00024d0e0)
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:720 +0x189
honnef.co/go/tools/lintcmd/runner.(*subrunner).do(0xc0000f5ae0, {0xd62210?, 0xc00024d0e0})
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:577 +0x948
honnef.co/go/tools/lintcmd/runner.(*Runner).Run.func2({0xd62210?, 0xc00024d0e0?})
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:1268 +0x2a
honnef.co/go/tools/lintcmd/runner.genericHandle({0xd62210?, 0xc00024d0e0}, {0xd62210?, 0xc00024cfc0?}, 0x8040102?, 0xc00047e4d0, 0xc000523880)
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:817 +0x113
created by honnef.co/go/tools/lintcmd/runner.(*Runner).Run in goroutine 1
        honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:1267 +0x4e5

I managed to boil it down to a single file containing the following:

package foo

import (
	"sync/atomic"
	"github.com/rcrowley/go-metrics"
)

var (
	sessionCount int64
	g = metrics.NewRegisteredFunctionalGauge("session_count", nil, func() int64 { return atomic.LoadInt64(&sessionCount) })
)

The issue doesn't occur if I switch to WSL (Ubuntu) and use the exact same staticcheck version (installed via Brew), so I guess this is a Windows specific issue.

  • staticcheck.exe 2023.1.5 (v0.4.5)
  • go version go1.21.0 windows/amd64
  • github.com/rcrowley/go-metrics@v0.0.0-20201227073835-cf1acfcdf475
set GO111MODULE=auto
set GOARCH=amd64
set GOCACHE=C:\Users\Nathan\AppData\Local\go-build
set GOENV=C:\Users\Nathan\AppData\Roaming\go\env
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOMODCACHE=C:\Users\Nathan\go\pkg\mod
set GOOS=windows
set GOPATH=C:\Users\Nathan\go
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\Nathan\scoop\apps\go\current
set GOSUMDB=sum.golang.org
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Users\Nathan\scoop\apps\go\current\pkg\tool\windows_amd64
set GOVERSION=go1.21.0
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=D:\Ryver\ryver\services\forseti\go.mod
set CGO_CFLAGS=-O2 -g
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\Nathan\AppData\Local\Temp\go-build3794376127=/tmp/go-build -gno-record-gcc-switches
@NathanBaulch NathanBaulch added bug needs-triage Newly filed issue that needs triage labels Aug 26, 2023
@dominikh dominikh removed the needs-triage Newly filed issue that needs triage label Aug 26, 2023
@dominikh
Copy link
Owner

The problem reproduces for me on linux/amd64, running actual Linux, not WSL.

@dominikh
Copy link
Owner

Are you sure you're building Staticcheck with Go 1.21.0 when experiencing the crash? I can reproduce the crash with Go master (at ff00fdfdbeeb72ca8981a04290765452d6a31b26), but not with Go 1.21.0.

Please include the output of staticcheck -debug.version.

dominikh added a commit that referenced this issue Aug 26, 2023
This pulls in changes in go/packages that are necessary to return
non-nil types.Sizes when using Go 1.22.

Closes: gh-1442
@stapelberg
Copy link

Hey @dominikh, the releases you provide are built with Go 1.22-devel, it seems. When starting a clean Docker container and installing Go 1.21, I can still reproduce the crash that you fixed:

% docker run -ti debian:testing bash
# apt update
# apt install golang-go git curl ca-certificates
# cd /usr/src
# curl -LO https://github.com/dominikh/go-tools/releases/download/2023.1.5/staticcheck_linux_amd64.tar.gz
# tar xf staticcheck_linux_amd64.tar.gz
# git clone https://github.com/protocolbuffers/protobuf-go/
# cd protobuf-go
# /usr/src/staticcheck/staticcheck ./types/dynamicpb
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5ff3ea]

goroutine 1331 [running]:
go/types.(*StdSizes).Sizeof(0x0, {0x9fed28?, 0xca37a0})
	go/types/sizes.go:228 +0x2ea
honnef.co/go/tools/staticcheck.checkAtomicAlignmentImpl(0xc000e76b40)
	honnef.co/go/tools@v0.4.5/staticcheck/lint.go:773 +0x65
honnef.co/go/tools/staticcheck.checkCalls.func1(0xc00011baa0?, {0xa06cb0?, 0xc001f5fd90}, 0xc001bf7540)
	honnef.co/go/tools@v0.4.5/staticcheck/lint.go:3293 +0x32d
honnef.co/go/tools/staticcheck.eachCall(0xc00044fe00, 0xc000762e00)
	honnef.co/go/tools@v0.4.5/staticcheck/lint.go:2662 +0x12b
honnef.co/go/tools/staticcheck.checkCalls(0xc0001cce40?, 0x4b348f?)
	honnef.co/go/tools@v0.4.5/staticcheck/lint.go:3334 +0x95
honnef.co/go/tools/staticcheck.init.makeCallCheckerAnalyzer.callChecker.func42(0x896020?)
	honnef.co/go/tools@v0.4.5/staticcheck/lint.go:3261 +0x17
honnef.co/go/tools/lintcmd/runner.(*analyzerRunner).do(0xc00176f590, {0xa02448?, 0xc001772820})
	honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:992 +0x71e
honnef.co/go/tools/lintcmd/runner.genericHandle({0xa02448?, 0xc001772820}, {0xa02448?, 0xc0012eac80?}, 0x0?, 0xc000492e90, 0xc0010033a0)
	honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:817 +0x113
created by honnef.co/go/tools/lintcmd/runner.(*subrunner).runAnalyzers in goroutine 1194
	honnef.co/go/tools@v0.4.5/lintcmd/runner/runner.go:1061 +0x6b5

# /usr/src/staticcheck/staticcheck -debug.version
staticcheck 2023.1.5 (v0.4.5)

Compiled with Go version: devel go1.22-7c2b69080a Thu Aug 10 17:34:27 2023 +0000
Main module:
	honnef.co/go/tools@v0.4.5 (sum: h1:YGD4H+SuIOOqsyoLOpZDWcieM28W47/zRO7f+9V3nvo=)
Dependencies:
	github.com/BurntSushi/toml@v1.2.1 (sum: h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=)
	golang.org/x/exp/typeparams@v0.0.0-20221208152030-732eee02a75a (sum: h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE=)
	golang.org/x/mod@v0.10.0 (sum: h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk=)
	golang.org/x/sys@v0.8.0 (sum: h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=)
	golang.org/x/tools@v0.9.4-0.20230601214343-86c93e8732cc (sum: h1:mqZawFxUzsv+YVwGQO30cZegeV/YD6dAwsdGxi0tQQg=)

Can you cut a new release which includes the fix please, and/or build releases with the latest stable version of Go, not an unreleased version? Thanks :)

dominikh added a commit that referenced this issue Sep 13, 2023
This pulls in changes in go/packages that are necessary to return
non-nil types.Sizes when using Go 1.22.

Closes: gh-1442
(cherry picked from commit 4670e26)
@dominikh
Copy link
Owner

@stapelberg Done.

@stapelberg
Copy link

Thanks for the quick fix! I can confirm it works for me now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants