8000 Data race in RandomString() · Issue #7 · dmgk/faker · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Data race in RandomString() #7

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

Closed
vladimiroff opened this issue Jul 20, 2018 · 1 comment
Closed

Data race in RandomString() #7

vladimiroff opened this issue Jul 20, 2018 · 1 comment

Comments

@vladimiroff
Copy link

When running tests which use this package with the race detector it finds out there are data races.
Trivial to reproduce example is with the following useless program:

package main

import "syreclabs.com/go/faker"

func main() {
	go faker.RandomString(10)
	go faker.RandomString(10)
}

When I run it with go run -race this is the output from go's race detector:

==================
WARNING: DATA RACE
Read at 0x00c42018afb8 by goroutine 7:
  math/rand.read()
      /usr/lib/go/src/math/rand/rand.go:265 +0x3c
  math/rand.(*Rand).Read()
      /usr/lib/go/src/math/rand/rand.go:261 +0x16d
  syreclabs.com/go/faker.RandomString()
      /home/kiril/go/src/syreclabs.com/go/faker/faker.go:90 +0xb2

Previous write at 0x00c42018afb8 by goroutine 6:
  math/rand.read()
      /usr/lib/go/src/math/rand/rand.go:276 +0xee
  math/rand.(*Rand).Read()
      /usr/lib/go/src/math/rand/rand.go:261 +0x16d
  syreclabs.com/go/faker.RandomString()
      /home/kiril/go/src/syreclabs.com/go/faker/faker.go:90 +0xb2

Goroutine 7 (running) created at:
  main.main()
      /tmp/fake.go:7 +0x6c

Goroutine 6 (finished) created at:
  main.main()
      /tmp/fake.go:6 +0x4b
==================
==================
WARNING: DATA RACE
Read at 0x00c42018afb0 by goroutine 7:
  math/rand.read()
      /usr/lib/go/src/math/rand/rand.go:266 +0x56
  math/rand.(*Rand).Read()
      /usr/lib/go/src/math/rand/rand.go:261 +0x16d
  syreclabs.com/go/faker.RandomString()
      /home/kiril/go/src/syreclabs.com/go/faker/faker.go:90 +0xb2

Previous write at 0x00c42018afb0 by goroutine 6:
  math/rand.read()
      /usr/lib/go/src/math/rand/rand.go:277 +0x108
  math/rand.(*Rand).Read()
      /usr/lib/go/src/math/rand/rand.go:261 +0x16d
  syreclabs.com/go/faker.RandomString()
      /home/kiril/go/src/syreclabs.com/go/faker/faker.go:90 +0xb2

Goroutine 7 (running) created at:
  main.main()
      /tmp/fake.go:7 +0x6c

Goroutine 6 (finished) created at:
  main.main()
      /tmp/fake.go:6 +0x4b
==================
Found 2 data race(s)
exit status 66

Now, this makes a lot of sense, since math/rand.Rand.Read is documented as not safe to be called concurrently. Which is okay for a method of type. RandomString in this package however is a global function and this issue could not be worked around as easily as with Rand.Read. For instance math/rand.Read (the global function) is safe to be called concurrently.

@dmgk dmgk closed this as completed in 552a925 Jul 20, 2018
@dmgk
Copy link
Owner
dmgk commented Jul 20, 2018

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0