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 condition error on batcher #46

Closed
peczenyj opened this issue Feb 19, 2024 · 1 comment · Fixed by #47
Closed

race condition error on batcher #46

peczenyj opened this issue Feb 19, 2024 · 1 comment · Fixed by #47

Comments

@peczenyj
Copy link

peczenyj commented Feb 19, 2024

Hello

we discover a possible race condition on batcher since version go-resiliency 1.4 and 1.5

Here is a minimal example with a test that trigger this issue

I tested with latest go (1.22) and go-resiliency 1.5

source code is available here https://github.com/peczenyj/example-race

package: https://github.com/peczenyj/example-race/blob/main/foo/foo.go

test: https://github.com/peczenyj/example-race/blob/main/foo/foo_test.go

$ go test -race ./foo/...
==================
WARNING: DATA RACE
Write at 0x00c00009eec8 by goroutine 7:
  github.com/eapache/go-resiliency/batcher.(*Batcher).submitWork()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/vendor/github.com/eapache/go-resiliency/batcher/batcher.go:74 +0xed
  github.com/eapache/go-resiliency/batcher.(*Batcher).Run()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/vendor/github.com/eapache/go-resiliency/batcher/batcher.go:55 +0x20e
  github.com/peczenyj/example-race/foo.(*Foo).Get()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/foo/foo.go:36 +0x2e7
  github.com/peczenyj/example-race/foo_test.TestBatcher()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/foo/foo_test.go:23 +0x2e8
  testing.tRunner()
      /usr/local/go1.22.0/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go1.22.0/src/testing/testing.go:1742 +0x44

Previous read at 0x00c00009eec8 by goroutine 8:
  github.com/eapache/go-resiliency/batcher.(*Batcher).batch()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/vendor/github.com/eapache/go-resiliency/batcher/batcher.go:100 +0x3d8
  github.com/eapache/go-resiliency/batcher.(*Batcher).submitWork.gowrap2()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/vendor/github.com/eapache/go-resiliency/batcher/batcher.go:76 +0x33

Goroutine 7 (running) created at:
  testing.(*T).Run()
      /usr/local/go1.22.0/src/testing/testing.go:1742 +0x825
  testing.runTests.func1()
      /usr/local/go1.22.0/src/testing/testing.go:2161 +0x85
  testing.tRunner()
      /usr/local/go1.22.0/src/testing/testing.go:1689 +0x21e
  testing.runTests()
      /usr/local/go1.22.0/src/testing/testing.go:2159 +0x8be
  testing.(*M).Run()
      /usr/local/go1.22.0/src/testing/testing.go:2027 +0xf17
  main.main()
      _testmain.go:49 +0x2bd

Goroutine 8 (finished) created at:
  github.com/eapache/go-resiliency/batcher.(*Batcher).submitWork()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/vendor/github.com/eapache/go-resiliency/batcher/batcher.go:76 +0x1ef
  github.com/eapache/go-resiliency/batcher.(*Batcher).Run()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/vendor/github.com/eapache/go-resiliency/batcher/batcher.go:55 +0x20e
  github.com/peczenyj/example-race/foo.(*Foo).Get()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/foo/foo.go:36 +0x283
  github.com/peczenyj/example-race/foo_test.TestBatcher()
      /home/weborama.office/tiago/work/go/src/github.com/peczenyj/example-race/foo/foo_test.go:22 +0x284
  testing.tRunner()
      /usr/local/go1.22.0/src/testing/testing.go:1689 +0x21e
  testing.(*T).Run.gowrap1()
      /usr/local/go1.22.0/src/testing/testing.go:1742 +0x44
==================
--- FAIL: TestBatcher (2.01s)
    testing.go:1398: race detected during execution of test
FAIL
FAIL	github.com/peczenyj/example-race/foo	2.017s
FAIL

while using go-resiliency 1.3 there is no race

$ go test -race ./foo/...
ok  	github.com/peczenyj/example-race/foo	3.016s

regards

@eapache
Copy link
Owner

eapache commented Feb 19, 2024

Thanks for the report, I made a few other small improvements while I was cleaning this up!

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

Successfully merging a pull request may close this issue.

2 participants