Skip to content

Commit

Permalink
update math_rand.Seed in dns scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoliang committed Jan 13, 2023
1 parent a4d880a commit 6003c8d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ var DNSScatterTransport = &http.Transport{
ExpectContinueTimeout: 1 * time.Second,
}

func init() {
math_rand.Seed(time.Now().UnixNano())
}

func DNSScatterDialContextFunc(ctx context.Context, network string, addr string) (conn net.Conn, err error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
Expand All @@ -59,7 +63,6 @@ func DNSScatterDialContextFunc(ctx context.Context, network string, addr string)
DualStack: true,
}
// DNS 打散
math_rand.Seed(time.Now().UnixNano())
start := math_rand.Intn(len(ips))
for i := start; i < len(ips); i++ {
conn, err = dialer.DialContext(ctx, network, net.JoinHostPort(ips[i].IP.String(), port))
Expand Down

0 comments on commit 6003c8d

Please sign in to comment.