@@ -536,31 +536,56 @@ func (g *LightningTerminal) start() error {
536
536
return fmt .Errorf ("error displaying startup info: %v" , err )
537
537
}
538
538
539
- // Wait for lnd to be unlocked, then start all clients.
540
- select {
541
- case <- readyChan :
539
+ // waitForSignal is a helper closure that can be used to wait on the
540
+ // given channel for a signal while also being responsive to an error
541
+ // from the error Queue, LND quiting or the interceptor receiving a
542
+ // shutdown signal.
543
+ waitForSignal := func (c chan struct {}) error {
544
+ select {
545
+ case <- c :
546
+ return nil
542
547
543
- case err := <- g .errQueue .ChanOut ():
544
- return err
548
+ case err := <- g .errQueue .ChanOut ():
549
+ return err
545
550
546
- case <- lndQuit :
547
- return nil
551
+ case <- lndQuit :
552
+ return nil
548
553
549
- case <- interceptor .ShutdownChannel ():
550
- return fmt .Errorf ("received the shutdown signal" )
554
+ case <- interceptor .ShutdownChannel ():
555
+ return fmt .Errorf ("received the shutdown signal" )
556
+ }
557
+ }
558
+
559
+ // Wait for lnd to be unlocked, then start all clients.
560
+ if err = waitForSignal (readyChan ); err != nil {
561
+ return err
551
562
}
552
563
553
564
// If we're in integrated mode, we'll need to wait for lnd to send the
554
565
// macaroon after unlock before going any further.
555
566
if g .cfg .LndMode == ModeIntegrated {
556
- <- bufReadyChan
557
- g .cfg .lndAdminMacaroon = <- macChan
567
+ if err = waitForSignal (bufReadyChan ); err != nil {
568
+ return err
569
+ }
570
+
571
+ // Create a new macReady channel that will serve to signal that
572
+ // the LND macaroon is ready. Spin off a goroutine that will
573
+ // close this channel when the macaroon has been received.
574
+ macReady := make (chan struct {})
575
+ go func () {
576
+ g .cfg .lndAdminMacaroon = <- macChan
577
+ close (macReady )
578
+ }()
579
+
580
+ if err = waitForSignal (macReady ); err != nil {
581
+ return err
582
+ }
558
583
}
559
584
560
585
// Set up all the LND clients required by LiT.
561
586
err = g .setUpLNDClients ()
562
587
if err != nil {
563
- log .Errorf ("Could not set up LND clients: %w " , err )
588
+ log .Errorf ("Could not set up LND clients: %v " , err )
564
589
return err
565
590
}
566
591
0 commit comments