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

Change to local 'rng' instead of global 'rng' #62

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import (
"time"
)

// Use a private rng so as not to mess with client application's seeds
var rng = rand.New(rand.NewSource(time.Now().UnixNano()))

// Handler is the message processing interface for Consumer
//
// Implement this interface for handlers that return whether or not message
Expand Down Expand Up @@ -293,6 +290,7 @@ func validatedLookupAddr(addr string) error {

// poll all known lookup servers every LookupdPollInterval
func (r *Consumer) lookupdLoop() {
var rng = rand.New(rand.NewSource(time.Now().UnixNano()))
// add some jitter so that multiple consumers discovering the same topic,
// when restarted at the same time, dont all connect at once.
jitter := time.Duration(int64(rng.Float64() *
Expand Down Expand Up @@ -618,6 +616,7 @@ func (r *Consumer) inBackoffBlock() bool {
}

func (r *Consumer) rdyLoop() {
var rng = rand.New(rand.NewSource(time.Now().UnixNano()))
var backoffTimer *time.Timer
var backoffTimerChan <-chan time.Time
var backoffCounter int32
Expand Down Expand Up @@ -725,7 +724,7 @@ func (r *Consumer) rdyLoop() {
}
}
case <-redistributeTicker.C:
r.redistributeRDY()
r.redistributeRDY(rng)
case <-r.exitChan:
goto exit
}
Expand Down Expand Up @@ -799,7 +798,7 @@ func (r *Consumer) sendRDY(c *Conn, count int64) error {
return nil
}

func (r *Consumer) redistributeRDY() {
func (r *Consumer) redistributeRDY(rng *rand.Rand) {
if r.inBackoffBlock() {
return
}
Expand Down