Skip to content

Commit

Permalink
Proxy use RWLock
Browse files Browse the repository at this point in the history
  • Loading branch information
alpinskiy committed Apr 27, 2024
1 parent 97aafd6 commit 982f6d7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions internal/aggregator/ingress_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,22 @@ func parseHostname(req []byte) (clientHost string, _ error) {
}

func (pool *clientPool) getClient(clientHost, remoteAddress string) *rpc.Client {
var client *rpc.Client
pool.mu.RLock()
client = pool.clients[clientHost]
pool.mu.RUnlock()
if client != nil {
return client
}
pool.mu.Lock()
defer pool.mu.Unlock()
client := pool.clients[clientHost]
if client == nil {
log.Printf("First connection from agent host: %s, host IP: %s", clientHost, remoteAddress)

client = rpc.NewClient(rpc.ClientWithLogf(log.Printf), rpc.ClientWithCryptoKey(pool.aesPwd), rpc.ClientWithTrustedSubnetGroups(build.TrustedSubnetGroups()))
pool.clients[clientHost] = client
client = pool.clients[clientHost]
if client != nil {
return client
}
log.Printf("First connection from agent host: %s, host IP: %s", clientHost, remoteAddress)
client = rpc.NewClient(rpc.ClientWithLogf(log.Printf), rpc.ClientWithCryptoKey(pool.aesPwd), rpc.ClientWithTrustedSubnetGroups(build.TrustedSubnetGroups()))
pool.clients[clientHost] = client
return client

}

0 comments on commit 982f6d7

Please sign in to comment.