From 9b2939d5381946152913706256dc6f2e8763fbbc Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 31 May 2021 09:44:38 +0300 Subject: [PATCH] [#567] cmd/node: Close cached clients on shutdown Call `CloseAll` on all `ClientCache` instances on application shutdown. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/container.go | 6 +++++- cmd/neofs-node/object.go | 2 ++ cmd/neofs-node/reputation.go | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/neofs-node/container.go b/cmd/neofs-node/container.go index 05ddc0b2..9ccb0c88 100644 --- a/cmd/neofs-node/container.go +++ b/cmd/neofs-node/container.go @@ -72,13 +72,15 @@ func initContainerService(c *cfg) { PlacementBuilder: loadPlacementBuilder, }) + clientCache := cache.NewSDKClientCache() // FIXME: use shared cache + loadRouter := loadroute.New( loadroute.Prm{ LocalServerInfo: c, RemoteWriterProvider: &remoteLoadAnnounceProvider{ key: c.key, loadAddrSrc: c, - clientCache: cache.NewSDKClientCache(), // FIXME: use shared cache + clientCache: clientCache, deadEndProvider: loadcontroller.SimpleWriterProvider(loadAccumulator), }, Builder: routeBuilder, @@ -86,6 +88,8 @@ func initContainerService(c *cfg) { loadroute.WithLogger(c.log), ) + c.onShutdown(clientCache.CloseAll) + ctrl := loadcontroller.New( loadcontroller.Prm{ LocalMetrics: loadcontroller.SimpleIteratorProvider(localMetrics), diff --git a/cmd/neofs-node/object.go b/cmd/neofs-node/object.go index 0ed2b339..825c0523 100644 --- a/cmd/neofs-node/object.go +++ b/cmd/neofs-node/object.go @@ -155,6 +155,8 @@ func initObjectService(c *cfg) { clientCache := cache.NewSDKClientCache( client.WithDialTimeout(c.viper.GetDuration(cfgAPIClientDialTimeout))) + c.onShutdown(clientCache.CloseAll) + clientConstructor := &reputationClientConstructor{ log: c.log, nmSrc: c.cfgObject.netMapStorage, diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 0011ed92..6084383a 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -90,6 +90,8 @@ func initReputationService(c *cfg) { apiClientCache := cache.NewSDKClientCache() + c.onShutdown(apiClientCache.CloseAll) + remoteLocalTrustProvider := common.NewRemoteTrustProvider( common.RemoteProviderPrm{ LocalAddrSrc: c,