Skip to content

Commit 488df78

Browse files
committed
lndclient: close trackpayment channels once final state is reached
When the server is finsihed sending updates in trackPayment, we get an EOF error. To allow clients to listen on these channels after the payment has succeeded, we close them to signal that we have finsihed sending updates.
1 parent 2ebbc78 commit 488df78

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lndclient/router_client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/rand"
66
"encoding/hex"
77
"fmt"
8+
"io"
89
"time"
910

1011
"github.com/btcsuite/btcutil"
@@ -225,6 +226,8 @@ func (r *routerClient) TrackPayment(ctx context.Context,
225226

226227
// trackPayment takes an update stream from either a SendPayment or a
227228
// TrackPayment rpc call and converts it into distinct update and error streams.
229+
// Once the payment reaches a final state, the status and error channels will
230+
// be closed to signal that we are finished sending into them.
228231
func (r *routerClient) trackPayment(ctx context.Context,
229232
stream routerrpc.Router_TrackPaymentV2Client) (chan PaymentStatus,
230233
chan error, error) {
@@ -235,6 +238,17 @@ func (r *routerClient) trackPayment(ctx context.Context,
235238
for {
236239
payment, err := stream.Recv()
237240
if err != nil {
241+
// If we get an EOF error, the payment has
242+
// reached a final state and the server is
243+
// finished sending us updates. We close both
244+
// channels to signal that we are done sending
245+
// values on them and return.
246+
if err == io.EOF {
247+
close(statusChan)
248+
close(errorChan)
249+
return
250+
}
251+
238252
switch status.Convert(err).Code() {
239253

240254
// NotFound is only expected as a response to

0 commit comments

Comments
 (0)