Use registeredServers slice copy during ServerInfo refreshing period (#2125)

goroutines:
proxy.updateRegisteredServers() versus proxy.serversInfo.refresh(proxy)
This commit is contained in:
lifenjoiner 2022-06-13 23:51:33 +08:00 committed by GitHub
parent 8d737a69f5
commit 6916c047e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -223,7 +223,9 @@ func (serversInfo *ServersInfo) refreshServer(proxy *Proxy, name string, stamp s
func (serversInfo *ServersInfo) refresh(proxy *Proxy) (int, error) {
dlog.Debug("Refreshing certificates")
serversInfo.RLock()
registeredServers := serversInfo.registeredServers
// Appending registeredServers slice from sources may allocate new memory.
registeredServers := make([]RegisteredServer, len(serversInfo.registeredServers))
copy(registeredServers, serversInfo.registeredServers)
serversInfo.RUnlock()
liveServers := 0
var err error