forked from TrueCloudLab/frostfs-node
[#567] network/clients: Implement method to close the cached clients
Update API Go library with introduce `Client.Conn` method. Implement `ClientCache.CloseAll` method which reads and closes connections of all cached clients. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
2e814941c0
commit
bf92e895c0
3 changed files with 19 additions and 1 deletions
2
go.mod
2
go.mod
|
@ -13,7 +13,7 @@ require (
|
||||||
github.com/multiformats/go-multiaddr v0.3.1
|
github.com/multiformats/go-multiaddr v0.3.1
|
||||||
github.com/nspcc-dev/hrw v1.0.9
|
github.com/nspcc-dev/hrw v1.0.9
|
||||||
github.com/nspcc-dev/neo-go v0.95.0
|
github.com/nspcc-dev/neo-go v0.95.0
|
||||||
github.com/nspcc-dev/neofs-api-go v1.26.2-0.20210528133202-6cd349738889
|
github.com/nspcc-dev/neofs-api-go v1.26.2-0.20210531071300-89be8d3f5ada
|
||||||
github.com/nspcc-dev/neofs-crypto v0.3.0
|
github.com/nspcc-dev/neofs-crypto v0.3.0
|
||||||
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210520210714-9dee13f0d556
|
github.com/nspcc-dev/neofs-sdk-go v0.0.0-20210520210714-9dee13f0d556
|
||||||
github.com/nspcc-dev/tzhash v1.4.0
|
github.com/nspcc-dev/tzhash v1.4.0
|
||||||
|
|
BIN
go.sum
BIN
go.sum
Binary file not shown.
18
pkg/network/cache/client.go
vendored
18
pkg/network/cache/client.go
vendored
|
@ -75,3 +75,21 @@ func (c *ClientCache) Get(netAddr *network.Address) (client.Client, error) {
|
||||||
|
|
||||||
return cli, nil
|
return cli, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseAll closes underlying connections of all cached clients.
|
||||||
|
//
|
||||||
|
// Ignores closing errors.
|
||||||
|
func (c *ClientCache) CloseAll() {
|
||||||
|
c.mu.RLock()
|
||||||
|
|
||||||
|
{
|
||||||
|
for _, cl := range c.clients {
|
||||||
|
con := cl.Conn()
|
||||||
|
if con != nil {
|
||||||
|
_ = con.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.mu.RUnlock()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue