Skip to content

Commit 57ee325

Browse files
committed
subservers: fail LiT startup when integrated sub-server boot fails
* Treat integrated sub-servers as fatal to startup and return an error if any fail to start. * Propagate integrated sub-server startup errors to LiT so it stops launching and records the failure status. * Update docs to reflect integrated sub-servers are now critical to startup.
1 parent 9e3ce65 commit 57ee325

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

subservers/interface.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import (
1414

1515
// SubServer defines an interface that should be implemented by any sub-server
1616
// that the subServer manager should manage. A sub-server can be run in either
17-
// integrated or remote mode. A sub-server is considered non-fatal to LiT
18-
// meaning that if a sub-server fails to start, LiT can safely continue with its
19-
// operations and other sub-servers can too.
17+
// integrated or remote mode. Integrated sub-servers are treated as critical to
18+
// LiT startup, meaning a failure to start any of them will abort the process.
2019
type SubServer interface {
2120
macaroons.MacaroonValidator
2221

subservers/manager.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/ioutil"
7+
"strings"
78
"sync"
89
"time"
910

@@ -104,13 +105,16 @@ func (s *Manager) GetServer(name string) (SubServer, bool) {
104105
}
105106

106107
// StartIntegratedServers starts all the manager's sub-servers that should be
107-
// started in integrated mode.
108+
// started in integrated mode. An error is returned if any integrated sub-server
109+
// fails to start.
108110
func (s *Manager) StartIntegratedServers(lndClient lnrpc.LightningClient,
109-
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) {
111+
lndGrpc *lndclient.GrpcLndServices, withMacaroonService bool) error {
110112

111113
s.mu.Lock()
112114
defer s.mu.Unlock()
113115

116+
var errs []string
117+
114118
for _, ss := range s.servers {
115119
if ss.Remote() {
116120
continue
@@ -126,11 +130,19 @@ func (s *Manager) StartIntegratedServers(lndClient lnrpc.LightningClient,
126130
)
127131
if err != nil {
128132
s.statusServer.SetErrored(ss.Name(), err.Error())
133+
errs = append(errs, fmt.Sprintf("%s: %v", ss.Name(), err))
129134
continue
130135
}
131136

132137
s.statusServer.SetRunning(ss.Name())
133138
}
139+
140+
if len(errs) > 0 {
141+
return fmt.Errorf("failed starting integrated sub-server(s): %s",
142+
strings.Join(errs, "; "))
143+
}
144+
145+
return nil
134146
}
135147

136148
// ConnectRemoteSubServers creates connections to all the manager's sub-servers

terminal.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,18 @@ func (g *LightningTerminal) start(ctx context.Context) error {
768768
// Both connection types are ready now, let's start our sub-servers if
769769
// they should be started locally as an integrated service.
770770
createDefaultMacaroons := !g.cfg.statelessInitMode
771-
g.subServerMgr.StartIntegratedServers(
771+
err = g.subServerMgr.StartIntegratedServers(
772772
g.basicClient, g.lndClient, createDefaultMacaroons,
773773
)
774+
if err != nil {
775+
g.statusMgr.SetErrored(
776+
subservers.LIT,
777+
"could not start integrated sub-servers: %v", err,
778+
)
779+
780+
return fmt.Errorf("could not start integrated sub-servers: %v",
781+
err)
782+
}
774783

775784
err = g.startInternalSubServers(ctx, !g.cfg.statelessInitMode)
776785
if err != nil {

0 commit comments

Comments
 (0)