Panic using random DistributingProducer with multiple producer threads
alicia-c opened this issue · comments
Looks like the issue may be that non-default instances of Rand are not thread-safe and the random DistributingProducer creates its own instance of rand.Rand
https://golang.org/pkg/math/rand/ : "The default Source is safe for concurrent use by multiple goroutines."
golang/go#3611 : "If you use your own Rand object, you must provide your own locking. The global Rand object used by Rand.Int31, et. al., does do locking itself. So I think this is a documentation issue."
Call stack below:
panic: runtime error: index out of range
goroutine 20 [running]:
math/rand.(_rngSource).Int63(0xc820100000, 0x7f4600000000)
C:/Go/src/math/rand/rng.go:244 +0xc1
math/rand.(_Rand).Int63(0xc8200dc8d0, 0x40fb16)
C:/Go/src/math/rand/rand.go:46 +0x39
math/rand.(_Rand).Int31(0xc8200dc8d0, 0x8)
C:/Go/src/math/rand/rand.go:52 +0x21
math/rand.(_Rand).Int31n(0xc8200dc8d0, 0xc800000006, 0x7f46914a9000)
C:/Go/src/math/rand/rand.go:87 +0xc1
math/rand.(_Rand).Intn(0xc8200dc8d0, 0x6, 0xc62)
C:/Go/src/math/rand/rand.go:101 +0x92
github.com/optiopay/kafka.(_randomProducer).Distribute(0xc8200e4640, 0x7ffcd0c13804, 0xa, 0xc82010a0e8, 0x1, 0x1, 0x55e0a0, 0x0, 0x0)
C:/Users/achin/Documents/goprojects/src/github.com/optiopay/kafka/distributing_producer.go:50 +0x4f