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

context: valueCtx's String panics if value is nil #68356

Closed
tchung1118 opened this issue Jul 9, 2024 · 2 comments
Closed

context: valueCtx's String panics if value is nil #68356

tchung1118 opened this issue Jul 9, 2024 · 2 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@tchung1118
Copy link

Go version

go version go1.23rc1 X:nocoverageredesign linux/amd64

Output of go env in your module/workspace:

GO111MODULE='off'
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT='nocoverageredesign'
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/user/go-code2/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/go-code2'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/.cache/bazel/_bazel_taiwon/a4cfce9b81ac8aa474cbfb97d6c4bc91/external/go_sdk'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/user/.cache/bazel/_bazel_taiwon/a4cfce9b81ac8aa474cbfb97d6c4bc91/external/go_sdk/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23rc1 X:nocoverageredesign'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD=''
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4074946335=/tmp/go-build -gno-record-gcc-switches'

What did you do?

Created a context via calling context.WithValue and passed nil to the value and tried printing:

ctx := context.WithValue(context.Background(), contextKey{}, nil)
fmt.Printf("%v\n", ctx)

Playground:
https://go.dev/play/p/vtF3t_JWxIC?v=gotip

What did you see happen?

Printed the following:

%!v(PANIC=String method: runtime error: invalid memory address or nil pointer dereference)

What did you expect to see?

In 1.22, the above program prints:

context.Background.WithValue(type main.contextKey, val <not Stringer>)
@seankhliao seankhliao added this to the Go1.23 milestone Jul 9, 2024
@seankhliao seankhliao added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 9, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/597415 mentions this issue: context: handle nil values for valueCtx.String()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants