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/race: race detector misses when copying into an interface #12664

Closed
jbardin opened this issue Sep 17, 2015 · 3 comments
Closed

runtime/race: race detector misses when copying into an interface #12664

jbardin opened this issue Sep 17, 2015 · 3 comments

Comments

@jbardin
Copy link
Contributor

jbardin commented Sep 17, 2015

The following is missed by the race detector

var (
    a = "hi"
    c = make(chan struct{})
)

func f() {
    a = "bye"
    close(c)
}

func main() {
    go f()
    fmt.Println(a)
    // fmt.Printf(a)
    <-c
}

But changing the fmt call to fmt.Printf where the a value is copied into the format string triggers a race

@jbardin jbardin changed the title runtime/race: race detector misses when copying into an interface{} runtime/race: race detector misses when copying into an interface Sep 17, 2015
@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Sep 17, 2015
@dvyukov
Copy link
Member

dvyukov commented Sep 18, 2015

Just tested on tip:

diff --git a/src/runtime/race/testdata/mop_test.go b/src/runtime/race/testdata/mop_test.go
index d7cbc98..af12c96 100644
--- a/src/runtime/race/testdata/mop_test.go
+++ b/src/runtime/race/testdata/mop_test.go
@@ -297,6 +297,17 @@ func TestRaceCaseTypeIssue5890(t *testing.T) {
        <-c
 }

+func TestRaceIssue12664(t *testing.T) {
+       a := "hi"
+       c := make(chan struct{})
+       go func() {
+               a = "bye"
+               close(c)
+       }()
+       fmt.Println(a)
+       <-c
+}
+
 func TestNoRaceRange(t *testing.T) {
        ch := make(chan int, 3)
        a := [...]int{1, 2, 3}

produces:

==================
WARNING: DATA RACE
Write by goroutine 7:
  command-line-arguments_test.TestRaceIssue12664.func1()
      src/runtime/race/testdata/mop_test.go:304 +0x2e

Previous read by goroutine 6:
  command-line-arguments_test.TestRaceIssue12664()
      src/runtime/race/testdata/mop_test.go:307 +0xc1
  testing.tRunner()
      src/testing/testing.go:456 +0xdc

Goroutine 7 (running) created at:
  command-line-arguments_test.TestRaceIssue12664()
      src/runtime/race/testdata/mop_test.go:306 +0xb3
  testing.tRunner()
      src/testing/testing.go:456 +0xdc

Goroutine 6 (running) created at:
  testing.RunTests()
      src/testing/testing.go:561 +0xaaf
  testing.(*M).Run()
      src/testing/testing.go:494 +0xe4
  main.main()
      command-line-arguments/_test/_testmain.go:312 +0x210
==================

go version devel +d5fe165 Fri Sep 18 07:15:52 2015 +0000 linux/amd64

@dvyukov
Copy link
Member

dvyukov commented Sep 18, 2015

But it in fact reproduces on the provided program. It seems to matter whether a is a global or not.

@gopherbot
Copy link

CL https://golang.org/cl/14752 mentions this issue.

@golang golang locked and limited conversation to collaborators Sep 22, 2016
@rsc rsc unassigned dvyukov Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants