Skip to content

Commit 0503cfd

Browse files
committed
session_rpcsever: thread context through
1 parent 1fc0e6f commit 0503cfd

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

session_rpcserver.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func newSessionRPCServer(cfg *sessionRpcServerConfig) (*sessionRpcServer,
9898

9999
// start all the components necessary for the sessionRpcServer to start serving
100100
// requests. This includes resuming all non-revoked sessions.
101-
func (s *sessionRpcServer) start() error {
101+
func (s *sessionRpcServer) start(ctx context.Context) error {
102102
// Start up all previously created sessions.
103103
sessions, err := s.cfg.db.ListSessions(nil)
104104
if err != nil {
@@ -135,7 +135,6 @@ func (s *sessionRpcServer) start() error {
135135
continue
136136
}
137137

138-
ctx := context.Background()
139138
ctxc, cancel := context.WithTimeout(
140139
ctx, defaultConnectTimeout,
141140
)
@@ -147,7 +146,7 @@ func (s *sessionRpcServer) start() error {
147146
cancel()
148147
if err != nil {
149148
log.Errorf("error activating autopilot "+
150-
"session (%x) with the client", key,
149+
"session (%x) with the client: %v", key,
151150
err)
152151

153152
if perm {
@@ -164,7 +163,7 @@ func (s *sessionRpcServer) start() error {
164163
}
165164
}
166165

167-
if err := s.resumeSession(sess); err != nil {
166+
if err := s.resumeSession(ctx, sess); err != nil {
168167
log.Errorf("error resuming session (%x): %v", key, err)
169168
}
170169
}
@@ -190,7 +189,7 @@ func (s *sessionRpcServer) stop() error {
190189
}
191190

192191
// AddSession adds and starts a new Terminal Connect session.
193-
func (s *sessionRpcServer) AddSession(_ context.Context,
192+
func (s *sessionRpcServer) AddSession(ctx context.Context,
194193
req *litrpc.AddSessionRequest) (*litrpc.AddSessionResponse, error) {
195194

196195
expiry := time.Unix(int64(req.ExpiryTimestampSeconds), 0)
@@ -335,7 +334,7 @@ func (s *sessionRpcServer) AddSession(_ context.Context,
335334
return nil, fmt.Errorf("error storing session: %v", err)
336335
}
337336

338-
if err := s.resumeSession(sess); err != nil {
337+
if err := s.resumeSession(ctx, sess); err != nil {
339338
return nil, fmt.Errorf("error starting session: %v", err)
340339
}
341340

@@ -351,7 +350,9 @@ func (s *sessionRpcServer) AddSession(_ context.Context,
351350

352351
// resumeSession tries to start an existing session if it is not expired, not
353352
// revoked and a LiT session.
354-
func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
353+
func (s *sessionRpcServer) resumeSession(ctx context.Context,
354+
sess *session.Session) error {
355+
355356
pubKey := sess.LocalPublicKey
356357
pubKeyBytes := pubKey.SerializeCompressed()
357358

@@ -423,15 +424,15 @@ func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
423424
})
424425

425426
mac, err := s.cfg.superMacBaker(
426-
context.Background(), sess.MacaroonRootKey,
427+
ctx, sess.MacaroonRootKey,
427428
&session.MacaroonRecipe{
428429
Permissions: permissions,
429430
Caveats: caveats,
430431
},
431432
)
432433
if err != nil {
433434
log.Debugf("Not resuming session %x. Could not bake "+
434-
"the necessary macaroon: %w", pubKeyBytes, err)
435+
"the necessary macaroon: %v", pubKeyBytes, err)
435436
return nil
436437
}
437438

@@ -516,7 +517,6 @@ func (s *sessionRpcServer) resumeSession(sess *session.Session) error {
516517
}
517518

518519
if s.cfg.autopilot != nil {
519-
ctx := context.Background()
520520
ctxc, cancel := context.WithTimeout(
521521
ctx, defaultConnectTimeout,
522522
)
@@ -1246,7 +1246,7 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12461246
return nil, fmt.Errorf("error storing session: %v", err)
12471247
}
12481248

1249-
if err := s.resumeSession(sess); err != nil {
1249+
if err := s.resumeSession(ctx, sess); err != nil {
12501250
return nil, fmt.Errorf("error starting session: %v", err)
12511251
}
12521252

terminal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func (g *LightningTerminal) start(ctx context.Context) error {
751751
g.basicClient, g.lndClient, createDefaultMacaroons,
752752
)
753753

754-
err = g.startInternalSubServers(!g.cfg.statelessInitMode)
754+
err = g.startInternalSubServers(ctx, !g.cfg.statelessInitMode)
755755
if err != nil {
756756
return fmt.Errorf("could not start litd sub-servers: %v", err)
757757
}
@@ -959,7 +959,7 @@ func (g *LightningTerminal) setUpLNDClients(ctx context.Context,
959959
}
960960

961961
// startInternalSubServers starts all Litd specific sub-servers.
962-
func (g *LightningTerminal) startInternalSubServers(
962+
func (g *LightningTerminal) startInternalSubServers(ctx context.Context,
963963
createDefaultMacaroons bool) error {
964964

965965
log.Infof("Starting LiT macaroon service")
@@ -1012,7 +1012,7 @@ func (g *LightningTerminal) startInternalSubServers(
10121012
}
10131013

10141014
log.Infof("Starting LiT session server")
1015-
if err = g.sessionRpcServer.start(); err != nil {
1015+
if err = g.sessionRpcServer.start(ctx); err != nil {
10161016
return err
10171017
}
10181018
g.sessionRpcServerStarted = true

0 commit comments

Comments
 (0)