Skip to content

terminal: dont block indefinitely on macaroon channel #616

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

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Changes from all commits
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
49 changes: 37 additions & 12 deletions terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,31 +536,56 @@ func (g *LightningTerminal) start() error {
return fmt.Errorf("error displaying startup info: %v", err)
}

// Wait for lnd to be unlocked, then start all clients.
select {
case <-readyChan:
// waitForSignal is a helper closure that can be used to wait on the
// given channel for a signal while also being responsive to an error
// from the error Queue, LND quiting or the interceptor receiving a
// shutdown signal.
waitForSignal := func(c chan struct{}) error {
select {
case <-c:
return nil

case err := <-g.errQueue.ChanOut():
return err
case err := <-g.errQueue.ChanOut():
return err

case <-lndQuit:
return nil
case <-lndQuit:
return nil

case <-interceptor.ShutdownChannel():
return fmt.Errorf("received the shutdown signal")
case <-interceptor.ShutdownChannel():
return fmt.Errorf("received the shutdown signal")
}
}

// Wait for lnd to be unlocked, then start all clients.
if err = waitForSignal(readyChan); err != nil {
return err
}

// If we're in integrated mode, we'll need to wait for lnd to send the
// macaroon after unlock before going any further.
if g.cfg.LndMode == ModeIntegrated {
<-bufReadyChan
g.cfg.lndAdminMacaroon = <-macChan
if err = waitForSignal(bufReadyChan); err != nil {
return err
}

// Create a new macReady channel that will serve to signal that
// the LND macaroon is ready. Spin off a goroutine that will
// close this channel when the macaroon has been received.
macReady := make(chan struct{})
go func() {
g.cfg.lndAdminMacaroon = <-macChan
close(macReady)
}()

if err = waitForSignal(macReady); err != nil {
return err
}
}

// Set up all the LND clients required by LiT.
err = g.setUpLNDClients()
if err != nil {
log.Errorf("Could not set up LND clients: %w", err)
log.Errorf("Could not set up LND clients: %v", err)
return err
}

Expand Down