From 823de8a5c4e930bb73411a847adacda8f938e15c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gregor=20Poga=C4=8Dnik?= <1640719+fiksn@users.noreply.github.com> Date: Fri, 17 Feb 2023 11:35:41 +0100 Subject: [PATCH] fix: fd leak when ingesting financial data (#37) --- cmd/bolt-agent/main.go | 5 +++++ data-upload/payments.go | 5 +++++ data-upload/sender.go | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/bolt-agent/main.go b/cmd/bolt-agent/main.go index ad8d201..bf12606 100644 --- a/cmd/bolt-agent/main.go +++ b/cmd/bolt-agent/main.go @@ -639,8 +639,13 @@ func sender(ctx context.Context, cmdCtx *cli.Context, apiKey string) { } func senderWithRetries(ctx context.Context, cmdCtx *cli.Context, apiKey string) error { + var permanent *backoff.PermanentError + sender, err := raw.MakeSender(ctx, apiKey, cmdCtx.String("datastore-url"), mkGetLndAPI(cmdCtx)) if err != nil { + if permanent.Is(err) { + return backoff.Permanent(fmt.Errorf("get GRPC fetcher failure %v", err)) + } return fmt.Errorf("get GRPC fetcher failure %v", err) } diff --git a/data-upload/payments.go b/data-upload/payments.go index 0b63b82..e59b4eb 100644 --- a/data-upload/payments.go +++ b/data-upload/payments.go @@ -26,6 +26,7 @@ func GetPaymentsChannel(ctx context.Context, lightning entities.NewAPICall, from if itf == nil { return nil, nil, fmt.Errorf("could not get lightning API") } + defer itf.Cleanup() return itf.GetPaymentsRaw(ctx, false, pagination) }), from, @@ -45,6 +46,7 @@ func GetInvoicesChannel(ctx context.Context, lightning entities.NewAPICall, from if itf == nil { return nil, nil, fmt.Errorf("could not get lightning API") } + defer itf.Cleanup() return itf.GetInvoicesRaw(ctx, false, pagination) }), from, @@ -62,6 +64,8 @@ func GetForwardsChannel(ctx context.Context, lightning entities.NewAPICall, from if itf != nil { // A hack to get failed forwards too + defer itf.Cleanup() + if itf.GetAPIType() == api.LndGrpc { lndGrpc, ok := itf.(*api.LndGrpcLightningAPI) if ok { @@ -81,6 +85,7 @@ func GetForwardsChannel(ctx context.Context, lightning entities.NewAPICall, from if itf == nil { return nil, nil, fmt.Errorf("could not get lightning API") } + defer itf.Cleanup() return itf.GetForwardsRaw(ctx, pagination) }), from, diff --git a/data-upload/sender.go b/data-upload/sender.go index 99cec76..780abf1 100644 --- a/data-upload/sender.go +++ b/data-upload/sender.go @@ -37,7 +37,7 @@ func toClientType(t api.APIType) int { // MakeSender creates a new Sender func MakeSender(ctx context.Context, authToken string, endpoint string, l entities.NewAPICall) (*Sender, error) { if l == nil { - return nil, fmt.Errorf("lightning API not specified") + return nil, backoff.Permanent(fmt.Errorf("lightning API not specified")) } f := &Sender{ AuthToken: authToken, @@ -46,8 +46,9 @@ func MakeSender(ctx context.Context, authToken string, endpoint string, l entiti api := l() if api == nil { - return nil, fmt.Errorf("lightning API not obtained") + return nil, backoff.Permanent(fmt.Errorf("lightning API not obtained")) } + defer api.Cleanup() info, err := api.GetInfo(ctx) if err != nil {