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

race conditions #27

Closed
luedigernet opened this issue Jan 9, 2020 · 1 comment
Closed

race conditions #27

luedigernet opened this issue Jan 9, 2020 · 1 comment

Comments

@luedigernet
Copy link

luedigernet commented Jan 9, 2020

When i looked into the code I was wondering if this package would be aware of go routines.
When it would be used in http handlers to handle calls of remote services , which is often the case in my implementation . The following test shows up that it is not aware of go routines even if there is a testcase in the package tests that tries to run them in parallel.

~/Desktop/Dev/go/sony/gobreaker:$ go test -race
==================
WARNING: DATA RACE
Read at 0x00c0001160d0 by goroutine 11:
  runtime.convT2Enoptr()
      /usr/local/go/src/runtime/iface.go:379 +0x0
  github.com/sony/gobreaker.TestCustomCircuitBreaker()
      /Users/rl/Desktop/Dev/go/sony/gobreaker/gobreaker_test.go:260 +0x11db
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:909 +0x199

Previous write at 0x00c0001160d0 by goroutine 12:
  github.com/sony/gobreaker.(*CircuitBreaker).beforeRequest()
      /Users/rl/Desktop/Dev/go/sony/gobreaker/gobreaker.go:56 +0x191
  github.com/sony/gobreaker.(*CircuitBreaker).Execute()
      /Users/rl/Desktop/Dev/go/sony/gobreaker/gobreaker.go:204 +0x63
  github.com/sony/gobreaker.succeedLater.func1()
      /Users/rl/Desktop/Dev/go/sony/gobreaker/gobreaker_test.go:38 +0x69

Goroutine 11 (running) created at:
  testing.(*T).Run()
      /usr/local/go/src/testing/testing.go:960 +0x651
  testing.runTests.func1()
      /usr/local/go/src/testing/testing.go:1202 +0xa6
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:909 +0x199
  testing.runTests()
      /usr/local/go/src/testing/testing.go:1200 +0x521
  testing.(*M).Run()
      /usr/local/go/src/testing/testing.go:1117 +0x2ff
  main.main()
      _testmain.go:58 +0x223

Goroutine 12 (running) created at:
  github.com/sony/gobreaker.succeedLater()
      /Users/rl/Desktop/Dev/go/sony/gobreaker/gobreaker_test.go:37 +0x82
  github.com/sony/gobreaker.TestCustomCircuitBreaker()
      /Users/rl/Desktop/Dev/go/sony/gobreaker/gobreaker_test.go:258 +0x113a
  testing.tRunner()
      /usr/local/go/src/testing/testing.go:909 +0x199
==================
--- FAIL: TestCustomCircuitBreaker (0.10s)
    testing.go:853: race detected during execution of test
FAIL
exit status 1
FAIL	github.com/sony/gobreaker	2.213s

What do you think about such a situation? Is it worth to invest in a PR to make it aware of go routines and in addition to that moving from the expensive sync.Mutex handling towards go channles so that always only one go routine is maintaining the counters and state?

@YoshiyukiMineo
Copy link
Member

gobreaker is goroutine-safe. You can run gobreaker in parallel.

The unit test is not goroutine-safe because it accesses the private members without mutex.
But actually you cannot access the private members outside the package.

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