mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-06 06:37:36 +03:00
Fix up the final error
This commit is contained in:
parent
f67cc14edd
commit
6efabc9ef3
1 changed files with 12 additions and 10 deletions
|
@ -224,27 +224,26 @@ func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
|
||||||
dlog.Debug("Refreshing certificates")
|
dlog.Debug("Refreshing certificates")
|
||||||
serversInfo.RLock()
|
serversInfo.RLock()
|
||||||
// Appending registeredServers slice from sources may allocate new memory.
|
// Appending registeredServers slice from sources may allocate new memory.
|
||||||
registeredServers := make([]RegisteredServer, len(serversInfo.registeredServers))
|
serversCount := len(serversInfo.registeredServers)
|
||||||
|
registeredServers := make([]RegisteredServer, serversCount)
|
||||||
copy(registeredServers, serversInfo.registeredServers)
|
copy(registeredServers, serversInfo.registeredServers)
|
||||||
serversInfo.RUnlock()
|
serversInfo.RUnlock()
|
||||||
|
|
||||||
countChannel := make(chan struct{}, proxy.certRefreshConcurrency)
|
countChannel := make(chan struct{}, proxy.certRefreshConcurrency)
|
||||||
waitChannel := make(chan struct{})
|
errorChannel := make(chan error, serversCount)
|
||||||
var err error
|
|
||||||
for i := range registeredServers {
|
for i := range registeredServers {
|
||||||
countChannel <- struct{}{}
|
countChannel <- struct{}{}
|
||||||
go func(registeredServer *RegisteredServer) {
|
go func(registeredServer *RegisteredServer) {
|
||||||
if err = serversInfo.refreshServer(proxy, registeredServer.name, registeredServer.stamp); err == nil {
|
err := serversInfo.refreshServer(proxy, registeredServer.name, registeredServer.stamp)
|
||||||
|
if err == nil {
|
||||||
proxy.xTransport.internalResolverReady = true
|
proxy.xTransport.internalResolverReady = true
|
||||||
}
|
}
|
||||||
|
errorChannel <- err
|
||||||
<-countChannel
|
<-countChannel
|
||||||
if len(countChannel) == 0 {
|
|
||||||
close(waitChannel)
|
|
||||||
}
|
|
||||||
}(®isteredServers[i])
|
}(®isteredServers[i])
|
||||||
}
|
}
|
||||||
if len(registeredServers) > 0 {
|
var err error
|
||||||
<-waitChannel
|
for i := 0; i < serversCount; i++ {
|
||||||
|
err = <-errorChannel
|
||||||
}
|
}
|
||||||
serversInfo.Lock()
|
serversInfo.Lock()
|
||||||
sort.SliceStable(serversInfo.inner, func(i, j int) bool {
|
sort.SliceStable(serversInfo.inner, func(i, j int) bool {
|
||||||
|
@ -262,6 +261,9 @@ 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)
|
dlog.Noticef("Server with the lowest initial latency: %s (rtt: %dms)", inner[0].Name, inner[0].initialRtt)
|
||||||
}
|
}
|
||||||
serversInfo.Unlock()
|
serversInfo.Unlock()
|
||||||
|
if innerLen > 0 {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
return innerLen, err
|
return innerLen, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue