Skip to content

Commit 1b10afd

Browse files
committed
rpcserver: remove session after registration error
1 parent a18c0b6 commit 1b10afd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

session_rpcserver.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,23 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12861286
privacyFlags.Serialize(),
12871287
)
12881288
if err != nil {
1289+
// If we tried to link to a previous session, we delete the
1290+
// newly created session in the case of errors to avoid having
1291+
// non-revoked sessions lying around.
1292+
if len(req.LinkedGroupId) != 0 {
1293+
log.Infof("Session registration with autopilot " +
1294+
"server failed, deleting the newly created " +
1295+
"session")
1296+
1297+
deleteErr := s.cfg.db.DeleteReservedSession(
1298+
ctx, sess.ID,
1299+
)
1300+
if deleteErr != nil {
1301+
log.Errorf("Error deleting session after "+
1302+
"failed linking attempt: %v", deleteErr)
1303+
}
1304+
}
1305+
12891306
return nil, fmt.Errorf("error registering session with "+
12901307
"autopilot server: %v", err)
12911308
}

0 commit comments

Comments
 (0)