-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
runtime: panic in mapaccess2_faststr (suspected data race) #65115
Comments
please include a runnable reproducer of the issue |
Hi @seankhliao , thank you for your response! Unfortunately, I cannot share you a runnable because it belongs to a private company. Could I share you another info that help you? |
I don't think this is because the map is nil. Based on the stack trace, it seems more like your strings are corrupted. Is your application using cgo, |
No, we are not using cgo, reflect.StringHeader neither unsafe.String. How can I know if the strings are corrupted? Is it possible that race conditions could produce that the strings are corrupted? |
Have you tried running the race detector on your code? |
That map variable is global, and is accessed by global functions, but there is no mutex. Global functions are generally expected to be concurrency-safe, so I suspect they were called from two concurrent goroutines, causing the the map data structure to become corrupted. Try running your tests with go test -race. |
Thank you all, I will try it 👍 |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
Go version
1.20
Output of
go env
in your module/workspace:{ "AR": "ar", "CC": "gcc", "CGO_CFLAGS": "-O2 -g", "CGO_CPPFLAGS": "", "CGO_CXXFLAGS": "-O2 -g", "CGO_ENABLED": "0", "CGO_FFLAGS": "-O2 -g", "CGO_LDFLAGS": "-O2 -g", "CXX": "g++", "GCCGO": "gccgo", "GO111MODULE": "", "GOAMD64": "v1", "GOARCH": "amd64", "GOBIN": "", "GOCACHE": "/root/.cache/go-build", "GOENV": "/root/.config/go/env", "GOEXE": "", "GOEXPERIMENT": "", "GOFLAGS": "", "GOGCCFLAGS": "-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build353150670=/tmp/go-build -gno-record-gcc-switches", "GOHOSTARCH": "amd64", "GOHOSTOS": "linux", "GOINSECURE": "", "GOMOD": "/go/src/bf/booking/go.mod", "GOMODCACHE": "/go/pkg/mod", "GONOPROXY": "gitlab.xmltravelgate.com", "GONOSUMDB": "gitlab.xmltravelgate.com", "GOOS": "linux", "GOPATH": "/go", "GOPRIVATE": "gitlab.xmltravelgate.com", "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.20.13", "GOWORK": "", "PKG_CONFIG": "pkg-config" }
What did you do?
Hi 😄!
I have tried to read a value from nil map
`var orgsToSendToPrometheus map[string]struct{}
func MustRegisterOverheadByOrg(org string) bool {
if _, ok := orgsToSendToPrometheus[allOrgs]; ok {
return true
}
_, ok := orgsToSendToPrometheus[org]
return ok
}`
What did you see happen?
I’m receiving a runtime error: invalid memory address or nil pointer dereference accessing to a nil map:
That panics in line → _, ok := orgsToSendToPrometheus[org]
As I understand, read , delete, length, and range loops, are safe to perform on a nil map since it behaves like an empty map.
All code:

Error trace:
The text was updated successfully, but these errors were encountered: