[#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>
This commit is contained in:
Alex Vanin 2021-07-13 14:02:24 +03:00 committed by Alex Vanin
parent 53391f057e
commit 38afb82926

View file

@ -324,9 +324,14 @@ func (x *multiClient) Close() error {
func (x *multiClient) RawForAddress(addr network.Address) *rawclient.Client { func (x *multiClient) RawForAddress(addr network.Address) *rawclient.Client {
x.mtx.Lock() 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() x.mtx.Unlock()
return c return c.Raw()
} }