Skip to content

Commit

Permalink
chore: stop subscription goroutines if node is stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Aug 5, 2024
1 parent fef85eb commit a4c177f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lnclient/lnd/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"io"
"math"
"sort"
"strconv"
Expand All @@ -14,6 +15,8 @@ import (

"github.com/btcsuite/btcd/chaincfg/chainhash"
decodepay "github.com/nbd-wtf/ln-decodepay"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/getAlby/hub/events"
"github.com/getAlby/hub/lnclient"
Expand Down Expand Up @@ -444,6 +447,12 @@ func NewLNDService(ctx context.Context, eventPublisher events.EventPublisher, ln
default:
payment, err := paymentStream.Recv()
if err != nil {
if grpcErr, ok := status.FromError(err); ok {
if grpcErr.Code() == codes.Unknown {
logger.Logger.Error("LND node stopped or unreachable, exiting payment subscription")
return
}
}
logger.Logger.WithError(err).Error("Failed to receive payment")
continue
}
Expand Down Expand Up @@ -501,6 +510,10 @@ func NewLNDService(ctx context.Context, eventPublisher events.EventPublisher, ln
default:
invoice, err := invoiceStream.Recv()
if err != nil {
if err == io.EOF {
logger.Logger.Error("LND node stopped or unreachable, exiting invoice subscription")
return
}
logger.Logger.WithError(err).Error("Failed to receive invoice")
continue
}
Expand Down

0 comments on commit a4c177f

Please sign in to comment.