[#567] innerring: Close cached clients on shutdown

Register `CloseAll` method to be called on IR application shutdown.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-31 09:51:06 +03:00 committed by Leonard Lyubich
parent 9b2939d538
commit 49a42b1d3e
2 changed files with 10 additions and 0 deletions

View file

@ -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) { func (s *Server) registerIOCloser(c io.Closer) {
s.registerCloser(c.Close) 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"), RangeTimeout: cfg.GetDuration("audit.timeout.rangehash"),
}) })
server.registerNoErrCloser(clientCache.cache.CloseAll)
pdpPoolSize := cfg.GetInt("audit.pdp.pairs_pool_size") pdpPoolSize := cfg.GetInt("audit.pdp.pairs_pool_size")
porPoolSize := cfg.GetInt("audit.por.pool_size") porPoolSize := cfg.GetInt("audit.por.pool_size")

View file

@ -23,6 +23,7 @@ type (
log *zap.Logger log *zap.Logger
cache interface { cache interface {
Get(address *network.Address) (client.Client, error) Get(address *network.Address) (client.Client, error)
CloseAll()
} }
key *ecdsa.PrivateKey key *ecdsa.PrivateKey