From 8c44da225a851e14d1f188b15a7bc3599c50dd09 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 16 Mar 2022 15:11:17 +0100 Subject: [PATCH] rpcwallet: fix RPC wallet health check connection leak Fixes #6329. This commit fixes a connection leak in the RPC wallet's health check. By not closing the test connection the watch-only node would slowly stack up connections and eventually hit the ulimit. --- lnwallet/rpcwallet/healthcheck.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lnwallet/rpcwallet/healthcheck.go b/lnwallet/rpcwallet/healthcheck.go index 27bcb9c73..7a412959e 100644 --- a/lnwallet/rpcwallet/healthcheck.go +++ b/lnwallet/rpcwallet/healthcheck.go @@ -11,7 +11,7 @@ import ( // configuration. func HealthCheck(cfg *lncfg.RemoteSigner, timeout time.Duration) func() error { return func() error { - _, err := connectRPC( + conn, err := connectRPC( cfg.RPCHost, cfg.TLSCertPath, cfg.MacaroonPath, timeout, ) if err != nil { @@ -19,6 +19,15 @@ func HealthCheck(cfg *lncfg.RemoteSigner, timeout time.Duration) func() error { "signing node through RPC: %v", err) } + defer func() { + err = conn.Close() + if err != nil { + log.Warnf("Failed to close health check "+ + "connection to remote signing node: %v", + err) + } + }() + return nil } }