-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
testing: racey access to t.failed #24438
Comments
Sent https://go-review.googlesource.com/c/go/+/101283 as the fix. |
Change https://golang.org/cl/101283 mentions this issue: |
Actually, not sure if this is an issue as you cannot fail the test after it exits. In the above output for the code, I would have expected to see a |
I've run into the same race. This appears to be a Go 1.10 regression from Go 1.9. Note: the docs are clear that
Here is my test case, which keeps the main test goroutine alive while the background goroutine calls t.Error: package main
import (
"testing"
"time"
)
func TestGoroutineError(t *testing.T) {
go func() {
t.Error("error from goroutine")
}()
time.Sleep(time.Second)
} I get this data race from running
I do not get a data race with Go 1.9.5:
I used the Go docker images to separately confirm that there is a data race with go1.10.1 linux/amd64 but no data race with go1.9 linux/amd64. |
Applying https://go-review.googlesource.com/c/go/+/101283 to my copy of the Go source does fix the regression. I don't know why the 32-bit trybots would have failed from that patch. |
Ping @ianlancetaylor - am I correct in my above comment that this is a 1.9 -> 1.10 regression? |
As far as I can tell this can only happen when there is a race condition between the call to So while I think this is likely worth fixing, since the race report isn't useful, it's not obvious to me that this is a regression as such. The test really is racy, and in principle the test could get the "Fail in goroutine after has completed" panic. If you have an example that is not racy, please let us know. |
Thanks for the explanation, I'm now satisfied that this is not a 1.9 -> 1.10 regression.
That's correct, this code does not trigger the race detector: package main
import (
"sync"
"testing"
)
func TestGoroutineError(t *testing.T) {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
t.Error("error from goroutine")
}()
wg.Wait()
} |
@ianlancetaylor why do you think the race report is not useful? It lets them know the test is racey. |
Yes, the test is racy, but not in a very interesting way. |
They might get the failure in goroutine after test exit panic like you said. Having the race detector also working to report the race makes them aware something is wrong too in case they do not get the panic. Its more protection. |
Please answer these questions before submitting your issue. Thanks!
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
)?What did you do?
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
Run with the race detector.
What did you expect to see?
No race condition.
What did you see instead?
Race condition.
Reason is that the variable read at
go/src/testing/testing.go
Line 790 in cc155eb
t.mu
is rlocked.The text was updated successfully, but these errors were encountered: