@@ -17,6 +17,9 @@ import (
17
17
log "github.com/cihub/seelog"
18
18
)
19
19
20
+ // Use a private rng so as not to mess with client application's seeds
21
+ var rng = rand .New (rand .NewSource (time .Now ().UnixNano ()))
22
+
20
23
// Handler is the synchronous interface to Reader.
21
24
//
22
25
// Implement this interface for handlers that return whether or not message
@@ -204,7 +207,6 @@ func (q *Reader) conns() []*Conn {
204
207
return conns
205
208
}
206
209
207
-
208
210
// ConnectionMaxInFlight calculates the per-connection max-in-flight count.
209
211
//
210
212
// This may change dynamically based on the number of connections to nsqd the Reader
@@ -301,9 +303,8 @@ func (q *Reader) ConnectToLookupd(addr string) error {
301
303
func (q * Reader ) lookupdLoop () {
302
304
// add some jitter so that multiple consumers discovering the same topic,
303
305
// when restarted at the same time, dont all connect at once.
304
- rand .Seed (time .Now ().UnixNano ())
305
306
306
- jitter := time .Duration (int64 (rand .Float64 () * q .LookupdPollJitter * float64 (q .LookupdPollInterval )))
307
+ jitter := time .Duration (int64 (rng .Float64 () * q .LookupdPollJitter * float64 (q .LookupdPollInterval )))
307
308
ticker := time .NewTicker (q .LookupdPollInterval )
308
309
309
310
select {
@@ -671,7 +672,7 @@ func (q *Reader) rdyLoop() {
671
672
if len (q .connections ) == 0 {
672
673
continue
673
674
}
674
- idx := rand .Intn (len (q .connections ))
675
+ idx := rng .Intn (len (q .connections ))
675
676
for _ , c := range q .connections {
676
677
if i == idx {
677
678
choice = c
@@ -884,7 +885,7 @@ func (q *Reader) redistributeRDY() {
884
885
885
886
for len (possibleConns ) > 0 && availableMaxInFlight > 0 {
886
887
availableMaxInFlight --
887
- i := rand .Int () % len (possibleConns )
888
+ i := rng .Int () % len (possibleConns )
888
889
c := possibleConns [i ]
889
890
// delete
890
891
possibleConns = append (possibleConns [:i ], possibleConns [i + 1 :]... )
0 commit comments