Skip to content

Commit

Permalink
Merge pull request #1163 from shenhui0509/master
Browse files Browse the repository at this point in the history
nsqd: add random load balancing for Authd query
  • Loading branch information
jehiah authored Jun 18, 2019
2 parents 223e97f + c711aa2 commit 1db3903
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion internal/auth/authorizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"log"
"math/rand"
"net/url"
"regexp"
"time"
Expand Down Expand Up @@ -78,7 +79,10 @@ func (a *State) IsExpired() bool {

func QueryAnyAuthd(authd []string, remoteIP string, tlsEnabled bool, commonName string, authSecret string,
connectTimeout time.Duration, requestTimeout time.Duration) (*State, error) {
for _, a := range authd {
start := rand.Int()
n := len(authd)
for i := 0; i < n; i++ {
a := authd[(i+start)%n]
authState, err := QueryAuthd(a, remoteIP, tlsEnabled, commonName, authSecret, connectTimeout, requestTimeout)
if err != nil {
log.Printf("Error: failed auth against %s %s", a, err)
Expand Down

0 comments on commit 1db3903

Please sign in to comment.