[#694] pkg/network: Use client cache in raw client getter

Every raw client getter invocation produced new connection, that lead
to connection leak.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
support/v0.27
Alex Vanin 2021-07-13 14:02:24 +03:00 committed by Alex Vanin
parent 53391f057e
commit 38afb82926
1 changed files with 7 additions and 2 deletions

View File

@ -324,9 +324,14 @@ func (x *multiClient) Close() error {
func (x *multiClient) RawForAddress(addr network.Address) *rawclient.Client {
x.mtx.Lock()
c := x.createForAddress(addr).Raw()
strAddr := addr.String()
c, cached := x.clients[strAddr]
if !cached {
c = x.createForAddress(addr)
}
x.mtx.Unlock()
return c
return c.Raw()
}