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

runtime: panic in mapaccess2_faststr (suspected data race) #65115

Open
mikimartin88 opened this issue Jan 16, 2024 · 7 comments
Open

runtime: panic in mapaccess2_faststr (suspected data race) #65115

mikimartin88 opened this issue Jan 16, 2024 · 7 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@mikimartin88
Copy link

mikimartin88 commented Jan 16, 2024

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:
image

Error trace:

/go/pkg/mod/gitlab.xmltravelgate.com/hub-aggregator/kit@v1.46.22/log/logger.go:68
gitlab.xmltravelgate.com/hub-aggregator/booking/common/kit/audit.Middleware.func1.1.1
/go/src/bf/booking/common/kit/audit/audit.go:119
runtime.gopanic
/usr/local/go/src/runtime/panic.go:884
runtime.panicmem
/usr/local/go/src/runtime/panic.go:260
runtime.sigpanic
/usr/local/go/src/runtime/signal_unix.go:841
memeqbody
/usr/local/go/src/internal/bytealg/equal_amd64.s:151
runtime.mapaccess2_faststr
/usr/local/go/src/runtime/map_faststr.go:133
gitlab.xmltravelgate.com/hub-aggregator/booking/common/connectx/hardCode.MustRegisterOverheadByOrg
/go/src/bf/booking/common/connectx/hardCode/operation_sla.go:30
gitlab.xmltravelgate.com/hub-aggregator/booking/pkg/flow/bfhttp.RegisterSLAStats
/go/src/bf/booking/pkg/flow/bfhttp/metric.go:178
gitlab.xmltravelgate.com/hub-aggregator/kit/http.(*Handler).ServeHTTP
/go/pkg/mod/gitlab.xmltravelgate.com/hub-aggregator/kit@v1.46.22/http/handler.go:90
gitlab.xmltravelgate.com/hub-aggregator/booking/common/connectx.TransactionMiddleware.func1.1
/go/src/bf/booking/common/connectx/transaction.go:124
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2122
github.com/travelgateX/go-jwt-tools.Middleware.func1.1
/go/pkg/mod/github.com/travelgate!x/go-jwt-tools@v1.5.0/auth.go:42
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2122
gitlab.xmltravelgate.com/hub-aggregator/tgx-kit/header.Middleware.func1.1
/go/pkg/mod/gitlab.xmltravelgate.com/hub-aggregator/tgx-kit@v1.77.68/header/header.go:235
net/http.HandlerFunc.ServeHTTP
/usr/local/go/src/net/http/server.go:2122```

### What did you expect to see?

No nil pointer reading over a map
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Jan 16, 2024
@seankhliao
Copy link
Member

please include a runnable reproducer of the issue

@seankhliao seankhliao added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 16, 2024
@mikimartin88
Copy link
Author

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?

@rittneje
Copy link

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, reflect.StringHeader, or unsafe.String?

@mikimartin88
Copy link
Author

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?

@rittneje
Copy link

Have you tried running the race detector on your code?

@seankhliao seankhliao added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 16, 2024
@adonovan
Copy link
Member

adonovan commented Jan 16, 2024

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.

@adonovan adonovan changed the title runtime: Nil pointer error reading map runtime: panic in mapaccess2_faststr (suspected data race) Jan 16, 2024
@mikimartin88
Copy link
Author

Thank you all, I will try it 👍

@seankhliao seankhliao added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jan 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
Status: No status
Development

No branches or pull requests

5 participants