You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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.
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.
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?
The text was updated successfully, but these errors were encountered: