-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime/metrics: data race detected in Read #53542
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
Comments
CC @golang/runtime |
I believe this is a false positive, as semacquire/semrelease aren't race instrumented. cc @mknyszek |
Given that readMetrics and initMetrics are both in package runtime (readMetrics is linknamed to runtime/metrics, but race instrumentation just looks at the package we're compiling), why did this get any race instrumentation at all? |
Oh, readMetrics didn't get any race instrumentation. The race instrumentation in this case is hand-coded in the map implementation (and hence insensitive to what package it's being called from). Probably we just need a little manual race instrumentation around the map usage in the metrics code. |
This isn't new in 1.19, so it doesn't have to be a release-blocker. It's also probably easy to fix, so for now I'll leave it marked just so we don't lose track. |
Change https://go.dev/cl/414517 mentions this issue: |
@gopherbot please backport to 1.17 and 1.18. This triggers a false positive in the race detector for programs calling |
Backport issue(s) opened: #53589 (for 1.17), #53590 (for 1.18). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Would it make sense to change the map functions to not call the race functions if the caller PC is in the runtime package? It would add the overhead of a PC lookup, but it can be limited to race mode, so maybe it could be acceptable? |
I don't think it is necessary. Maps aren't too widely used in the runtime, and I'd prefer us to be able to expand the number of races in the runtime rather than turning it off. It would be nice to catch these quicker though. |
I recall Windows callback is another place that uses a map and causes false race, #50249 . |
Argh. I sent a fix for that too, but that one is nastier because it is called prior to scheduler initialization, which is fine for the raceread/racewrite in the map, but not raceacquire/racerelease. |
That one does me a bit more inclined to turn it off in the map. |
FWIW, I did a quick benchmark. A non-race map access is ~3ns. A race map access is ~17ns. With an additional runtime pc check (for This isn't horrible given we're in race mode, but it is still pretty large. [1] My map was in runtime_test, so the string comparison had to go through most of the characters before failing. |
Thanks for the benchmark. There are a few places where we check whether a PC is in the runtime. Maybe we could provide a 1-bit metadata for whether a function is a runtime function, to avoid the string comparison. But I guess in this case most of the overhead is probably the PC lookup, instead of the string comparison. Maybe we could make it simply an address range comparison, as the linker already lay out runtime functions together (mostly, I think). |
Change https://go.dev/cl/415195 mentions this issue: |
Change https://go.dev/cl/415196 mentions this issue: |
metricsSema protects the metrics map. The map implementation is race instrumented regardless of which package is it called from. semacquire/semrelease are not automatically race instrumented, so we can trigger race false positives without manually annotating our lock acquire and release. See similar instrumentation on trace.shutdownSema and reflectOffs.lock. Fixes #53589. For #53542. Change-Id: Ia3fd239ac860e037d09c7cb9c4ad267391e70705 Reviewed-on: https://go-review.googlesource.com/c/go/+/414517 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> (cherry picked from commit d6481d5) Reviewed-on: https://go-review.googlesource.com/c/go/+/415196
metricsSema protects the metrics map. The map implementation is race instrumented regardless of which package is it called from. semacquire/semrelease are not automatically race instrumented, so we can trigger race false positives without manually annotating our lock acquire and release. See similar instrumentation on trace.shutdownSema and reflectOffs.lock. Fixes #53590. For #53542. Change-Id: Ia3fd239ac860e037d09c7cb9c4ad267391e70705 Reviewed-on: https://go-review.googlesource.com/c/go/+/414517 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> (cherry picked from commit d6481d5) Reviewed-on: https://go-review.googlesource.com/c/go/+/415195
metricsSema protects the metrics map. The map implementation is race instrumented regardless of which package is it called from. semacquire/semrelease are not automatically race instrumented, so we can trigger race false positives without manually annotating our lock acquire and release. See similar instrumentation on trace.shutdownSema and reflectOffs.lock. Fixes golang#53590. For golang#53542. Change-Id: Ia3fd239ac860e037d09c7cb9c4ad267391e70705 Reviewed-on: https://go-review.googlesource.com/c/go/+/414517 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> (cherry picked from commit d6481d5) Reviewed-on: https://go-review.googlesource.com/c/go/+/415195
metricsSema protects the metrics map. The map implementation is race instrumented regardless of which package is it called from. semacquire/semrelease are not automatically race instrumented, so we can trigger race false positives without manually annotating our lock acquire and release. See similar instrumentation on trace.shutdownSema and reflectOffs.lock. Fixes golang#53542. Change-Id: Ia3fd239ac860e037d09c7cb9c4ad267391e70705 Reviewed-on: https://go-review.googlesource.com/c/go/+/414517 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, still reproducible with 1.19beta1.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
runtime/metrics
says that "It is safe to execute multiple Read calls concurrently". However, running the following code with race detector enabled suggests a data race. Unsure whether this is a false positive (metrics.Read
uses a semaphore lock).What did you expect to see?
No race detected.
What did you see instead?
Data race detected.
The text was updated successfully, but these errors were encountered: