Skip to content

Commit

Permalink
fix: fd leak when ingesting financial data (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
fiksn authored Feb 17, 2023
1 parent a1e181f commit 823de8a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions cmd/bolt-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 5 additions & 0 deletions data-upload/payments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions data-upload/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 823de8a

Please sign in to comment.