Skip to content

Commit 207d443

Browse files
author
livingentity
authored
Update serversInfo.go (#2092)
1 parent 3eac156 commit 207d443

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

dnscrypt-proxy/serversInfo.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,14 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
251251
return liveServers, err
252252
}
253253

254-
func (serversInfo *ServersInfo) estimatorUpdate() {
254+
func (serversInfo *ServersInfo) estimatorUpdate(currentActive int) {
255255
// serversInfo.RWMutex is assumed to be Locked
256256
serversCount := len(serversInfo.inner)
257257
activeCount := serversInfo.lbStrategy.getActiveCount(serversCount)
258258
if activeCount == serversCount {
259259
return
260260
}
261-
candidate, currentActive := rand.Intn(serversCount-activeCount)+activeCount, rand.Intn(activeCount)
261+
candidate := rand.Intn(serversCount-activeCount)+activeCount
262262
candidateRtt, currentActiveRtt := serversInfo.inner[candidate].rtt.Value(), serversInfo.inner[currentActive].rtt.Value()
263263
if currentActiveRtt < 0 {
264264
currentActiveRtt = candidateRtt
@@ -297,10 +297,10 @@ func (serversInfo *ServersInfo) getOne() *ServerInfo {
297297
serversInfo.Unlock()
298298
return nil
299299
}
300+
candidate := serversInfo.lbStrategy.getCandidate(serversCount)
300301
if serversInfo.lbEstimator {
301-
serversInfo.estimatorUpdate()
302+
serversInfo.estimatorUpdate(candidate)
302303
}
303-
candidate := serversInfo.lbStrategy.getCandidate(serversCount)
304304
serverInfo := serversInfo.inner[candidate]
305305
dlog.Debugf("Using candidate [%s] RTT: %d", (*serverInfo).Name, int((*serverInfo).rtt.Value()))
306306
serversInfo.Unlock()

0 commit comments

Comments
 (0)