diff --git a/cmd/loop/debug.go b/cmd/loop/debug.go index 9bb17106..e2f7318c 100644 --- a/cmd/loop/debug.go +++ b/cmd/loop/debug.go @@ -48,11 +48,10 @@ func getDebugClient(ctx context.Context, cmd *cli.Command) (looprpc.DebugClient, if err != nil { return nil, nil, err } - conn, err := getClientConn(rpcServer, tlsCertPath, macaroonPath) + conn, cleanup, err := getClientConn(rpcServer, tlsCertPath, macaroonPath) if err != nil { return nil, nil, err } - cleanup := func() { conn.Close() } debugClient := looprpc.NewDebugClient(conn) return debugClient, cleanup, nil diff --git a/cmd/loop/main.go b/cmd/loop/main.go index 873a198d..d12fdea9 100644 --- a/cmd/loop/main.go +++ b/cmd/loop/main.go @@ -251,11 +251,10 @@ func getClientWithConn(cmd *cli.Command) (looprpc.SwapClientClient, if err != nil { return nil, nil, nil, err } - conn, err := getClientConn(rpcServer, tlsCertPath, macaroonPath) + conn, cleanup, err := getClientConn(rpcServer, tlsCertPath, macaroonPath) if err != nil { return nil, nil, nil, err } - cleanup := func() { conn.Close() } loopClient := looprpc.NewSwapClientClient(conn) return loopClient, conn, cleanup, nil @@ -465,12 +464,12 @@ func logSwap(swap *looprpc.SwapStatus) { } func getClientConn(address, tlsCertPath, macaroonPath string) (*grpc.ClientConn, - error) { + func(), error) { // We always need to send a macaroon. macOption, err := readMacaroon(macaroonPath) if err != nil { - return nil, err + return nil, nil, err } opts := []grpc.DialOption{ @@ -481,18 +480,22 @@ func getClientConn(address, tlsCertPath, macaroonPath string) (*grpc.ClientConn, // Since TLS cannot be disabled, we'll always have a cert file to read. creds, err := credentials.NewClientTLSFromFile(tlsCertPath, "") if err != nil { - return nil, err + return nil, nil, err } opts = append(opts, grpc.WithTransportCredentials(creds)) conn, err := grpc.NewClient(address, opts...) if err != nil { - return nil, fmt.Errorf("unable to create RPC client: %v", + return nil, nil, fmt.Errorf("unable to create RPC client: %v", err) } - return conn, nil + cleanup := func() { + _ = conn.Close() + } + + return conn, cleanup, nil } // readMacaroon tries to read the macaroon file at the specified path and create