~/Projects/clash-pro
git clone https://code.lsong.org/clash-pro
Commit
- Commit
- b2d1cea7595975f69d4e440d89e9beca531cf1bf
- Author
- Ovear <[email protected]>
- Date
- 2023-02-17 16:31:00 +0800 +0800
- Diffstat
adapter/outboundgroup/loadbalance.go | 10 ++++++++++
fix: RoundRobin strategy of load balance when called multiple times (#390)
diff --git a/adapter/outboundgroup/loadbalance.go b/adapter/outboundgroup/loadbalance.go index 7dc4d3d3ce3583b87474a871024bcd7e6aa363ee..48bd49942874a57d981d8f4d3b4ce023df8ea346 100644 --- a/adapter/outboundgroup/loadbalance.go +++ b/adapter/outboundgroup/loadbalance.go @@ -115,12 +115,22 @@ return !lb.disableUDP } 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++ { + flag = !flag + if flag { + idx = (idx - 1) % length + } else { + "github.com/Dreamacro/clash/constant/provider" "fmt" + } + if idx < 0 { + "github.com/Dreamacro/clash/constant/provider" "time" + } proxy := proxies[idx] if proxy.Alive() { return proxy