-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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/race: running with -race misses races (mismatch with memory model) #37355
Comments
cc @dvyukov |
Change https://golang.org/cl/220419 mentions this issue: |
Change https://golang.org/cl/226981 mentions this issue: |
Update race detector syso files for some platforms. There's still 2 more to do, but they might take a while so I'm mailing the ones I have now. Note: some arm64 tests did not complete successfully due to out of memory errors, but I suspect the .syso is correct. Update #14481 Update #37485 (I think?) Update #37355 Change-Id: I7e7e707a1fd7574855a538ba89dc11acc999c760 Reviewed-on: https://go-review.googlesource.com/c/go/+/226981 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Change https://golang.org/cl/227443 mentions this issue: |
Update #14881 Update #37355 Change-Id: I5edd53b7532836cfe6037fb668b1b8fe8f7a32f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/227443 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Change https://golang.org/cl/227867 mentions this issue: |
Tsan changes are in, but the Go side isn't done yet. |
Change https://golang.org/cl/231222 mentions this issue: |
Change https://golang.org/cl/231297 mentions this issue: |
Update #37355 Change-Id: I90cc121c158a9d44df01772083a7a9301598532e Reviewed-on: https://go-review.googlesource.com/c/go/+/231297 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Update race detector syso files for some platforms. There's still 2 more to do, but they might take a while so I'm mailing the ones I have now. Note: some arm64 tests did not complete successfully due to out of memory errors, but I suspect the .syso is correct. For #14481 For #37485 (I think?) For #37355 Fixes #38321 Change-Id: I7e7e707a1fd7574855a538ba89dc11acc999c760 Reviewed-on: https://go-review.googlesource.com/c/go/+/226981 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> (cherry picked from commit 041bcb3) Reviewed-on: https://go-review.googlesource.com/c/go/+/231222 Reviewed-by: Keith Randall <khr@golang.org>
Change https://golang.org/cl/232159 mentions this issue: |
For #14881 For #37355 For #38321 Change-Id: I5edd53b7532836cfe6037fb668b1b8fe8f7a32f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/227443 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> (cherry picked from commit 7a35d39) Reviewed-on: https://go-review.googlesource.com/c/go/+/232159 Reviewed-by: Keith Randall <khr@golang.org>
Change https://golang.org/cl/232417 mentions this issue: |
For #14481 For #37355 For #38321 Change-Id: Idfceaf0e64d340b7304ce9562549a82ebfc27e3c Reviewed-on: https://go-review.googlesource.com/c/go/+/227867 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> (cherry picked from commit 3afa741) Reviewed-on: https://go-review.googlesource.com/c/go/+/232417 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Update golang#37355 Change-Id: I90cc121c158a9d44df01772083a7a9301598532e Reviewed-on: https://go-review.googlesource.com/c/go/+/231297 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Reopening because CL 220419 is being reverted; see #42598. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do
This issue was found from inspecting the code in
chan.go
as opposed to observing behavior during execution. I did created a program to illustrate the issue. I believe the program (shown below) is racy, but the race detector does not flag the race (no output in stdout/stderr).(I believe the culprit are four lines of code in
chan.go
, as detailed in "What did you expect", with a patch suggested at the end.)The program is as follows:
$ cat test_chan.go
What did you observe
I observed no output. The program does not print to stdout or stderr and, when running the program with the race checker enabled, the race checker also does not produce any output.
What did you expect instead
I expected the race checker to flag a race between the write in t1 and the write in t4.
The program can (and often does) produce the following trace:
The question is: are the two writes,
wr(2,z)
andwr(4,z)
, in a race?According to the memory model:
rv(2,c)
happens-before the completion ofsd(3,c)
,sd(3,c)
happens-before the completion ofrv(4,c)
,rv(2,c)
is not in happens-before with respect torv(4,c)
. They are not in happens-before relation becausesd(3,c)
and the completion ofsd(3,c)
are not the same. Thus we cannot use transitivity of happens-before to derive a relation betweenrv(2,c)
andrv(4,c)
.This race is not flagged by the race detector. I believe the race detector interpret the events as follows:
rv(2,c)
happens-beforesd(3,c)
sd(3,c)
happens-beforerv(4,c)
rv(2,c)
is in happens-before with respect torv(4,c)
, thus the write by thread 2 is in the past of the write by thread 4.Instead of not getting any output when running the program with race check enabled, I expected to see output like this:
The output above is from the following patch:
Consider the following piece of code present in both
chansend()
andchanrecv()
functions ofruntime/chan.go
:If in
chansend()
, theraceacquire()
comes beforeracerelease()
, then a thread gains happens-before information (via theraceacquire
) before the completion of the send operation, as opposed to at the point of completion as specified by the memory model. Similar for the order ofraceacquire()
andracereceive()
inchanrevc()
.In practice, having
raceacquire()
beforeracerelease()
can prevent the race detector from flagging certain race conditions, such as the race condition illustrated with the example program and trace above.The fix is simple: just swap the order of
raceacquire()
andracerelease()
in bothchansend()
andchanrecv()
functions ofruntime/chan.go
:The patch passes the tests in
all.bash
.In more detail...
Another way to look at the trace above is by transforming the sends and receives into sequences of acquire and releases. If the sends and receives are interpreted as
raceacquire(); racerelease()
as it is currently the case inchan.go
, then the trace would be as shown below, and a race detector will not flag the trace as racy:The absence of a race in the trace above comes from the fact that we can find a happens-before chain from
wr(2,z)
towr(4,z)
:wr(2,z)
is in happens-before withrel(2,c)
by program orderrel(2,c)
is in happens-before withacq(3,c)
andrel(3,c)
by lock semantics and program orderrel(3,c)
is in happens-before withacq(4,c)
by lock semanticsacq(4,c)
is in happens-before withwr(4,z)
by program orderIf, however, we swap the order of the
raceacquire()
andracerelease()
in the interpretation of sends and receives, then a race detector will then report the trace as racy. The race exists because, given the trace below, it is not possible to derive that the write from thread 2 is in happens-before with respect to the write from thread 4.The text was updated successfully, but these errors were encountered: