Skip to content

math/rand: use of Read is racy #16308

@yonderblue

Description

@yonderblue

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    1.7rc1
  2. What operating system and processor architecture are you using (go env)?
    linux amd64
  3. What did you do?
    Ran a large concurrent unit test.
  4. What did you expect to see?
    Bunnies
  5. What did you see instead?
WARNING: DATA RACE
Write at 0x00c420098098 by goroutine 65:
  math/rand.(*Rand).Seed()
      /usr/local/go/src/math/rand/rand.go:54 +0x6d
  math/rand.Seed()
      /usr/local/go/src/math/rand/rand.go:202 +0x54
  XXX/XXX_test.TestXXX.func2()
      /go/src/XXX/XXX_test.go:359 +0x163

Previous write at 0x00c420098098 by goroutine 66:
  math/rand.(*Rand).Seed()
      /usr/local/go/src/math/rand/rand.go:54 +0x6d
  math/rand.Seed()
      /usr/local/go/src/math/rand/rand.go:202 +0x54
  XXX/XXX_test.TestXXX.func2()
      /go/src/XXX/XXX_test.go:359 +0x163

Goroutine 65 (running) created at:
  XXX/XXX_test.TestXXX()
      /go/src/XXX/XXX_test.go:389 +0x8c2
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:610 +0xc9

Goroutine 66 (running) created at:
  XXX/XXX_test.TestXXX()
      /go/src/XXX/XXX_test.go:389 +0x8c2
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:610 +0xc9
==================
==================
WARNING: DATA RACE
Read at 0x00c420098090 by goroutine 65:
  math/rand.(*Rand).Read()
      /usr/local/go/src/math/rand/rand.go:177 +0x6a
  math/rand.Read()
      /usr/local/go/src/math/rand/rand.go:248 +0x6c
  XXX/XXX_test.TestXXX.func2()
      /go/src/XXX/XXX_test.go:360 +0x188

Previous write at 0x00c420098090 by goroutine 66:
  math/rand.(*Rand).Read()
      /usr/local/go/src/math/rand/rand.go:188 +0x127
  math/rand.Read()
      /usr/local/go/src/math/rand/rand.go:248 +0x6c
  XXX/XXX_test.TestXXX.func2()
      /go/src/XXX/XXX_test.go:360 +0x188

Goroutine 65 (running) created at:
  XXX/XXX_test.TestXXX()
      /go/src/XXX/XXX_test.go:389 +0x8c2
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:610 +0xc9

Goroutine 66 (running) created at:
  XXX/XXX_test.TestXXX()
      /go/src/XXX/XXX_test.go:389 +0x8c2
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:610 +0xc9
==================

I can confirm it does not happen on 1.6, at least with my runs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions