aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2021-11-12 11:00:20 -0500
committerGravatar GitHub <noreply@github.com> 2021-11-12 16:00:20 +0000
commit29cae579325e5968343d665f02f8d961624f9481 (patch)
treed14d5413bf41339adc754ea20849facc0cec7852 /plugin
parentf6ffafe229a7269b9824e14a85eda8bc8474aef7 (diff)
downloadcoredns-29cae579325e5968343d665f02f8d961624f9481.tar.gz
coredns-29cae579325e5968343d665f02f8d961624f9481.tar.zst
coredns-29cae579325e5968343d665f02f8d961624f9481.zip
plugin/loadbalance: More consistent shuffling (#4961)
* fix shuffling Signed-off-by: Chris O'Haver <cohaver@infoblox.com> * shuffle each record once Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin')
-rw-r--r--plugin/loadbalance/loadbalance.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/plugin/loadbalance/loadbalance.go b/plugin/loadbalance/loadbalance.go
index 3f3049202..0d67d3e4a 100644
--- a/plugin/loadbalance/loadbalance.go
+++ b/plugin/loadbalance/loadbalance.go
@@ -61,13 +61,12 @@ func roundRobinShuffle(records []dns.RR) {
records[0], records[1] = records[1], records[0]
}
default:
- for j := 0; j < l*(int(dns.Id())%4+1); j++ {
- q := int(dns.Id()) % l
- p := int(dns.Id()) % l
- if q == p {
- p = (p + 1) % l
+ for j := 0; j < l; j++ {
+ p := j + (int(dns.Id()) % (l-j))
+ if j == p {
+ continue
}
- records[q], records[p] = records[p], records[q]
+ records[j], records[p] = records[p], records[j]
}
}
}