fix: RoundRobin strategy of load balance when called multiple times (#390)

This commit is contained in:
Ovear 2023-02-17 16:31:00 +08:00 committed by GitHub
parent 6fe1766c83
commit b2d1cea759
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,11 +115,20 @@ func (lb *LoadBalance) SupportUDP() bool {
}
func strategyRoundRobin() strategyFn {
flag := true
idx := 0
return func(proxies []C.Proxy, metadata *C.Metadata) C.Proxy {
length := len(proxies)
for i := 0; i < length; i++ {
idx = (idx + 1) % length
flag = !flag
if flag {
idx = (idx - 1) % length
} else {
idx = (idx + 2) % length
}
if idx < 0 {
idx = idx + length
}
proxy := proxies[idx]
if proxy.Alive() {
return proxy