From 8f35cc7c00b2928fe2d5dff8f0fb134c02e33695 Mon Sep 17 00:00:00 2001 From: YX Hao Date: Sun, 17 Dec 2023 11:27:32 +0800 Subject: [PATCH] Return successfully updated live servers count `serversInfo.inner` may contain "dead" servers. --- dnscrypt-proxy/serversInfo.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/dnscrypt-proxy/serversInfo.go b/dnscrypt-proxy/serversInfo.go index 45dda97e..d247583c 100644 --- a/dnscrypt-proxy/serversInfo.go +++ b/dnscrypt-proxy/serversInfo.go @@ -241,9 +241,16 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) { <-countChannel }(®isteredServers[i]) } + liveServers := 0 var err error for i := 0; i < serversCount; i++ { err = <-errorChannel + if err == nil { + liveServers++ + } + } + if liveServers > 0 { + err = nil } serversInfo.Lock() sort.SliceStable(serversInfo.inner, func(i, j int) bool { @@ -261,10 +268,7 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) { dlog.Noticef("Server with the lowest initial latency: %s (rtt: %dms)", inner[0].Name, inner[0].initialRtt) } serversInfo.Unlock() - if innerLen > 0 { - err = nil - } - return innerLen, err + return liveServers, err } func (serversInfo *ServersInfo) estimatorUpdate(currentActive int) {