Skip to content

Commit da3ae1a

Browse files
committed
rpcserver: remove session after registration error
1 parent 48f5fe0 commit da3ae1a

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

session_rpcserver.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,10 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12051205
return nil, fmt.Errorf("error creating new session: %v", err)
12061206
}
12071207

1208+
fail := func(err error) error {
1209+
return err
1210+
}
1211+
12081212
// If this session is being linked to a previous one, then we need to
12091213
// use the previous session's local private key to sign the new
12101214
// session's public key in order to prove to the Autopilot server that
@@ -1278,8 +1282,19 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12781282
privacyFlags.Serialize(),
12791283
)
12801284
if err != nil {
1281-
return nil, fmt.Errorf("error registering session with "+
1282-
"autopilot server: %v", err)
1285+
// If we tried to link to a previous session, we delete the
1286+
// newly created session in the case of errors to avoid having
1287+
// non-revoked sessions lying around.
1288+
if len(req.LinkedGroupId) != 0 {
1289+
deleteErr := s.cfg.db.DeleteReservedSession(
1290+
ctx, sess.ID,
1291+
)
1292+
log.Errorf("error deleting session after failed "+
1293+
"linking attempt: %v", deleteErr)
1294+
}
1295+
1296+
return nil, fail(fmt.Errorf("error registering session with "+
1297+
"autopilot server: %v", err))
12831298
}
12841299

12851300
err = s.cfg.db.UpdateSessionRemotePubKey(ctx, sess.ID, remoteKey)

0 commit comments

Comments
 (0)