From 67438bd006bb58518b59f19a831268c75eefe304 Mon Sep 17 00:00:00 2001 From: Matheus Degiovani Date: Mon, 16 Dec 2019 17:32:45 -0300 Subject: [PATCH] lntest: Don't leak node's grpc conn This changes the HarnessNode structure to hold onto the client grpc connection made during startup so that it can close it during shutdown. This is needed because the grpc.Dial function spins a new goroutine that attempts to maintain an open connection to the target endpoint and without calling Close() in the connection while shutting down the node we leak this goroutine to the rest of the tests. --- lntest/node.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lntest/node.go b/lntest/node.go index b6636089d..df34db468 100644 --- a/lntest/node.go +++ b/lntest/node.go @@ -272,6 +272,9 @@ type HarnessNode struct { invoicesrpc.InvoicesClient + // conn is the underlying connection to the grpc endpoint of the node. + conn *grpc.ClientConn + // RouterClient, WalletKitClient, WatchtowerClient cannot be embedded, // because a name collision would occur with LightningClient. RouterClient routerrpc.RouterClient @@ -552,6 +555,7 @@ func (hn *HarnessNode) Unlock(ctx context.Context, func (hn *HarnessNode) initLightningClient(conn *grpc.ClientConn) error { // Construct the LightningClient that will allow us to use the // HarnessNode directly for normal rpc operations. + hn.conn = conn hn.LightningClient = lnrpc.NewLightningClient(conn) hn.InvoicesClient = invoicesrpc.NewInvoicesClient(conn) hn.RouterClient = routerrpc.NewRouterClient(conn) @@ -790,6 +794,15 @@ func (hn *HarnessNode) stop() error { hn.WalletUnlockerClient = nil hn.Watchtower = nil hn.WatchtowerClient = nil + + // Close any attempts at further grpc connections. + if hn.conn != nil { + err := hn.conn.Close() + if err != nil { + return fmt.Errorf("error attempting to stop grpc client: %v", err) + } + } + return nil }