mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-04 21:57:44 +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")
|
||||
serversInfo.RLock()
|
||||
// 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)
|
||||
serversInfo.RUnlock()
|
||||
|
||||
countChannel := make(chan struct{}, proxy.certRefreshConcurrency)
|
||||
waitChannel := make(chan struct{})
|
||||
var err error
|
||||
errorChannel := make(chan error, serversCount)
|
||||
for i := range registeredServers {
|
||||
countChannel <- struct{}{}
|
||||
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
|
||||
}
|
||||
errorChannel <- err
|
||||
<-countChannel
|
||||
if len(countChannel) == 0 {
|
||||
close(waitChannel)
|
||||
}
|
||||
}(®isteredServers[i])
|
||||
}
|
||||
if len(registeredServers) > 0 {
|
||||
<-waitChannel
|
||||
var err error
|
||||
for i := 0; i < serversCount; i++ {
|
||||
err = <-errorChannel
|
||||
}
|
||||
serversInfo.Lock()
|
||||
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)
|
||||
}
|
||||
serversInfo.Unlock()
|
||||
if innerLen > 0 {
|
||||
err = nil
|
||||
}
|
||||
return innerLen, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue