Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: stop subscription goroutines if node is stopped #404

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codes.Unknown feels wrong, but we should otherwise use grpcErr.Message() == "routerrpc server shutting down" which looks hacky, what should I do here?

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
Loading