From 6b2fc5e056974bec870db386c8e1e6be2b89cebd Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 1 Jul 2022 23:07:37 +0300 Subject: [PATCH] rpc/client: add Close method Allow to close unused network connections and use it during RPC broadcaster shutdown, because otherwise we leak them. --- pkg/rpc/client/client.go | 5 +++++ pkg/services/helpers/rpcbroadcaster/client.go | 1 + 2 files changed, 6 insertions(+) diff --git a/pkg/rpc/client/client.go b/pkg/rpc/client/client.go index fb03f4bd8..a837e5238 100644 --- a/pkg/rpc/client/client.go +++ b/pkg/rpc/client/client.go @@ -167,6 +167,11 @@ func (c *Client) Init() error { return nil } +// Close closes unused underlying networks connections. +func (c *Client) Close() { + c.cli.CloseIdleConnections() +} + func (c *Client) performRequest(method string, p request.RawParams, v interface{}) error { var r = request.Raw{ JSONRPC: request.JSONRPCVersion, diff --git a/pkg/services/helpers/rpcbroadcaster/client.go b/pkg/services/helpers/rpcbroadcaster/client.go index 1045312b0..33696084f 100644 --- a/pkg/services/helpers/rpcbroadcaster/client.go +++ b/pkg/services/helpers/rpcbroadcaster/client.go @@ -66,6 +66,7 @@ run: } } } + c.client.Close() drain: for { select {