Skip to content

Commit ef296e9

Browse files
authored
Merge pull request #377 from bhandras/chainnoitifer_fix
loop: wait for chain notifier server to start
2 parents 5d39ffe + a0b67da commit ef296e9

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

executor.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package loop
33
import (
44
"context"
55
"fmt"
6+
"strings"
67
"sync"
78
"sync/atomic"
89
"time"
@@ -52,10 +53,37 @@ func newExecutor(cfg *executorConfig) *executor {
5253
func (s *executor) run(mainCtx context.Context,
5354
statusChan chan<- SwapInfo) error {
5455

55-
blockEpochChan, blockErrorChan, err :=
56-
s.lnd.ChainNotifier.RegisterBlockEpochNtfn(mainCtx)
57-
if err != nil {
58-
return err
56+
var (
57+
err error
58+
blockEpochChan <-chan int32
59+
blockErrorChan <-chan error
60+
)
61+
62+
for {
63+
blockEpochChan, blockErrorChan, err =
64+
s.lnd.ChainNotifier.RegisterBlockEpochNtfn(mainCtx)
65+
if err != nil {
66+
if strings.Contains(err.Error(),
67+
"in the process of starting") {
68+
69+
log.Warnf("LND chain notifier server not " +
70+
"ready yet, retrying with delay")
71+
72+
// Give chain notifier some time to start and
73+
// try to re-attempt block epoch subscription.
74+
select {
75+
case <-time.After(500 * time.Millisecond):
76+
continue
77+
78+
case <-mainCtx.Done():
79+
return err
80+
}
81+
}
82+
83+
return err
84+
}
85+
86+
break
5987
}
6088

6189
// Before starting, make sure we have an up to date block height.

0 commit comments

Comments
 (0)