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 | Bin 61151 -> 61151 bytes pkg/network/cache/client.go | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 88751208..21a26c12 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 6ae40af0bf5d6b0c31c26d02a2db03220d5386ff..0c8a5ef70cc29bee68eb935767f54c9231cd7bc6 100644 GIT binary patch delta 112 zcmcbAm-+r(<_%wRosA6*%ngkV40J6llTs~GjMGdLQxX+246XFjDvRB7LiLR;BmJGU x4U=4gsuGJbOgut-%!;&~j8pUt^b6b#O}v6rCMy(5O!m){6~$`S=El6Z1^_S}BbERF delta 113 zcmcbAm-+r(<_%wRU5qRYjg5^AjC9SCQ;bb4&5bQAEG!i=46XbMDso-TO8kSXBK%yE y1B^@DtCI6VEIp!(JoLRi3Ovh9UCf-Ew4(}rTqi3Qicj{>lNH5k*yhH(xCQ`40V6R0 diff --git a/pkg/network/cache/client.go b/pkg/network/cache/client.go index b386c32e..2e77ada0 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() +}