From bf92e895c0735cb9a76f507b16a05abbad7c8876 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 31 May 2021 09:43:35 +0300 Subject: [PATCH] [#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 --- go.mod | 2 +- go.sum | 4 ++-- pkg/network/cache/client.go | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 88751208e..21a26c12a 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/multiformats/go-multiaddr v0.3.1 github.com/nspcc-dev/hrw v1.0.9 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-sdk-go v0.0.0-20210520210714-9dee13f0d556 github.com/nspcc-dev/tzhash v1.4.0 diff --git a/go.sum b/go.sum index 6ae40af0b..0c8a5ef70 100644 --- a/go.sum +++ b/go.sum @@ -286,8 +286,8 @@ github.com/nspcc-dev/neo-go v0.95.0 h1:bttArYkIuhBJWSZsZ1xVW8MJsj5SvZwAhqVN3HZPN github.com/nspcc-dev/neo-go v0.95.0/go.mod h1:bW07ge1WFXsBgqrcPpLUr6OcyQxHqM26MZNesWMdH0c= github.com/nspcc-dev/neofs-api-go v1.24.0/go.mod h1:G7dqincfdjBrAbL5nxVp82emF05fSVEqe59ICsoRDI8= github.com/nspcc-dev/neofs-api-go v1.26.1/go.mod h1:SHuH1Ba3U/h3j+8HHbb3Cns1LfMlEb88guWog9Qi68Y= -github.com/nspcc-dev/neofs-api-go v1.26.2-0.20210528133202-6cd349738889 h1:NpxmE6tOSzXNDcP3tGzcnT9HZ2H/KHpIv5D6BB+ZqLE= -github.com/nspcc-dev/neofs-api-go v1.26.2-0.20210528133202-6cd349738889/go.mod h1:SHuH1Ba3U/h3j+8HHbb3Cns1LfMlEb88guWog9Qi68Y= +github.com/nspcc-dev/neofs-api-go v1.26.2-0.20210531071300-89be8d3f5ada h1:/fysGlU/39YOB+1bDRzarh4HTL6r+B3d/0/pG14JSdw= +github.com/nspcc-dev/neofs-api-go v1.26.2-0.20210531071300-89be8d3f5ada/go.mod h1:SHuH1Ba3U/h3j+8HHbb3Cns1LfMlEb88guWog9Qi68Y= github.com/nspcc-dev/neofs-crypto v0.2.0/go.mod h1:F/96fUzPM3wR+UGsPi3faVNmFlA9KAEAUQR7dMxZmNA= github.com/nspcc-dev/neofs-crypto v0.2.3/go.mod h1:8w16GEJbH6791ktVqHN9YRNH3s9BEEKYxGhlFnp0cDw= github.com/nspcc-dev/neofs-crypto v0.3.0 h1:zlr3pgoxuzrmGCxc5W8dGVfA9Rro8diFvVnBg0L4ifM= diff --git a/pkg/network/cache/client.go b/pkg/network/cache/client.go index b386c32ed..2e77ada0b 100644 --- a/pkg/network/cache/client.go +++ b/pkg/network/cache/client.go @@ -75,3 +75,21 @@ func (c *ClientCache) Get(netAddr *network.Address) (client.Client, error) { 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() +}