Go version
go version go1.25.0 darwin/arm64
Output of go env
in your module/workspace:
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/redacted/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/redacted/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/m4/sr146z197b1df6lgmh2gkqbw0000gq/T/go-build2415365221=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/redacted/projects/demos/jsondump/go.mod'
GOMODCACHE='/Users/redacted/go/pkg/mod'
GONOPROXY='redacted'
GONOSUMDB='redacted'
GOOS='darwin'
GOPATH='/Users/redacted/go'
GOPRIVATE='redacted'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/redacted/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.darwin-arm64'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/redacted/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/redacted/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.25.0.darwin-arm64/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.0'
GOWORK=''
PKG_CONFIG='pkg-config'
What did you do?
Run:
GOEXPERIMENT=jsonv2 /usr/local/go/bin/go env -json
In a folder with the following go.mod
module something
go 1.25
In the absence of the above go.mod
file, go version
returns go version go1.24.1 darwin/arm64
.
As for why I'm doing this:
I am trying to experiment with the new encoding/json/v2
and related packages, so I've configured VS Code to have the following settings.json
, so that I don't get red-squiggles in my IDE and so auto-complete works:
{
"go.toolsEnvVars": {
"GOEXPERIMENT": "jsonv2"
},
"go.testEnvVars": {
"GOEXPERIMEN": "jsonv2"
}
}
During started, gopls
runs go env -json GOPATH GOROOT GOPROXY GOBIN GOMODCACHE
, but crashes because of the GOEXPERIMENT env-var.
(I don't actually know if the above settings are enough to make my IDE do what I want - it's what I tried and it crashed)
What did you see happen?
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x3 pc=0x10316aa40]
goroutine 1 [running]:
cmd/go/internal/fips140.Init()
cmd/go/internal/fips140/fips140.go:117 +0x120
cmd/go/internal/modload.Init()
cmd/go/internal/modload/init.go:419 +0x38
cmd/go/internal/toolchain.Exec({0x140000aca68, 0x8})
cmd/go/internal/toolchain/select.go:356 +0x46c
cmd/go/internal/toolchain.Select()
cmd/go/internal/toolchain/select.go:284 +0xf28
main.main()
cmd/go/main.go:107 +0x58
I'm not sure exactly which go-executable broke (1.24.1 or 1.25.0). I'm guessing 1.25.0, otherwise the GOEXPERIMENT=jsonv2
shouldn't have done anything?
What did you expect to see?
Something like:
{
"AR": "ar",
"CC": "clang",
"CGO_CFLAGS": "-O2 -g",
"CGO_CPPFLAGS": "",
"CGO_CXXFLAGS": "-O2 -g",
"CGO_ENABLED": "1",
"CGO_FFLAGS": "-O2 -g",
"CGO_LDFLAGS": "-O2 -g",
"CXX": "clang++",
"GCCGO": "gccgo",
"GO111MODULE": "",
"GOARCH": "arm64",
"GOARM64": "v8.0",
// ...
}
Comment From: dmitshur
CC @dsnet, @neild.
Comment From: seankhliao
I think we need more info on reproducing this:
cmd/go should return an error of go: unknown GOEXPERIMENT jsonv2
if it doesn't know about an experiment (e.g. 1.24 doesn't know about jsonv2), but that shouldn't prevent it from doing a version switch to 1.25 and returning an answer.
Comment From: aslatter
What more info would you be looking for?
Here's a minimal repro (modulo everything else on my machine, I guess):
mkdir tmp
cd tmp
go version
printf "module something\ngo 1.25\n" > go.mod
GOEXPERIMENT=jsonv2 go env -json
The output is:
go version go1.24.1 darwin/arm64
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x3 pc=0x100dd2a40]
goroutine 1 [running]:
cmd/go/internal/fips140.Init()
cmd/go/internal/fips140/fips140.go:117 +0x120
cmd/go/internal/modload.Init()
cmd/go/internal/modload/init.go:419 +0x38
cmd/go/internal/toolchain.Exec({0x140000aca58, 0x8})
cmd/go/internal/toolchain/select.go:356 +0x46c
cmd/go/internal/toolchain.Select()
cmd/go/internal/toolchain/select.go:284 +0xf28
main.main()
cmd/go/main.go:107 +0x58
Comment From: dmitshur
It sounds this happens when the toolchain selection is involved, as it doesn't happen with a local go1.25.0 toolchain. Can you try it again with GODEBUG=toolchaintrace=1
and see if that adds helpful information for seeing at which point this happens? Well, while typing the above it turned out quick enough for me to try:
$ GOEXPERIMENT=jsonv2 GODEBUG=toolchaintrace=1 go env -json
go: upgrading toolchain to go1.25.0 (required by go line in go.mod; upgrade allowed by GOTOOLCHAIN=auto)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x3 pc=0x102ae2a40]
goroutine 1 [running]:
cmd/go/internal/fips140.Init()
cmd/go/internal/fips140/fips140.go:117 +0x120
cmd/go/internal/modload.Init()
cmd/go/internal/modload/init.go:419 +0x38
cmd/go/internal/toolchain.Exec({0x14000010a50, 0x8})
cmd/go/internal/toolchain/select.go:356 +0x46c
cmd/go/internal/toolchain.Select()
cmd/go/internal/toolchain/select.go:284 +0xf28
main.main()
cmd/go/main.go:107 +0x58
I also see it happens with go version
, go env
, too, not just go env -json
.
This is likely similar to past issues like #74111 and #61455. CC @golang/command-line, @prattmic.
Comment From: aslatter
FYI if I upgrade my base install to Go 1.24.6, the problem goes away. I can downgrade back to 1.24.1, but if it is a bug that has been fixed there probably isn't anything that can be done.
Comment From: dmitshur
Maybe this issue is exactly the same as #74111. The fix for that was backported to Go 1.24.5. Can you see if it happens with Go 1.24.4 but not 1.24.5?
Comment From: aslatter
I think the JSON flag is a red-herring - I just made assumptions based on the json experiment. I get the crash without the -json flag, and my stack-trace looks the same as what's in #74111, and I get the same error with a nonsense GOEXPERIMENT value.
If your spidey-senses are still giving you reason to worry I can try more versions, but my guess is I won't learn anything.
Comment From: dmitshur
Sounds good, let's close it as a duplicate of that issue. Thanks for the report.