From 49a42b1d3e0b088db3aea896c8a7c1a356436e82 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 31 May 2021 09:51:06 +0300 Subject: [PATCH] [#567] innerring: Close cached clients on shutdown Register `CloseAll` method to be called on IR application shutdown. Signed-off-by: Leonard Lyubich --- pkg/innerring/innerring.go | 9 +++++++++ pkg/innerring/rpc.go | 1 + 2 files changed, 10 insertions(+) diff --git a/pkg/innerring/innerring.go b/pkg/innerring/innerring.go index c57cbe6f..1a829023 100644 --- a/pkg/innerring/innerring.go +++ b/pkg/innerring/innerring.go @@ -235,6 +235,13 @@ func (s *Server) Stop() { } } +func (s *Server) registerNoErrCloser(c func()) { + s.registerCloser(func() error { + c() + return nil + }) +} + func (s *Server) registerIOCloser(c io.Closer) { s.registerCloser(c.Close) } @@ -393,6 +400,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error RangeTimeout: cfg.GetDuration("audit.timeout.rangehash"), }) + server.registerNoErrCloser(clientCache.cache.CloseAll) + pdpPoolSize := cfg.GetInt("audit.pdp.pairs_pool_size") porPoolSize := cfg.GetInt("audit.por.pool_size") diff --git a/pkg/innerring/rpc.go b/pkg/innerring/rpc.go index 45130612..3d812d2d 100644 --- a/pkg/innerring/rpc.go +++ b/pkg/innerring/rpc.go @@ -23,6 +23,7 @@ type ( log *zap.Logger cache interface { Get(address *network.Address) (client.Client, error) + CloseAll() } key *ecdsa.PrivateKey