Skip to content

Commit d131076

Browse files
committed
rpcserver: remove session after registration error
1 parent b57779a commit d131076

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

session_rpcserver.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,18 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12131213
return nil, fmt.Errorf("error creating new session: %v", err)
12141214
}
12151215

1216+
// If we tried to link to a previous session, we delete the newly
1217+
// created session in the case of errors to avoid having non-revoked
1218+
// sessions lying around.
1219+
fail := func(err error) error {
1220+
if len(req.LinkedGroupId) != 0 {
1221+
err := s.cfg.db.DeleteReservedSession(ctx, sess.ID)
1222+
log.Errorf("error deleting session after failed "+
1223+
"linking attempt: %v", err)
1224+
}
1225+
return err
1226+
}
1227+
12161228
// If this session is being linked to a previous one, then we need to
12171229
// use the previous session's local private key to sign the new
12181230
// session's public key in order to prove to the Autopilot server that
@@ -1286,8 +1298,8 @@ func (s *sessionRpcServer) AddAutopilotSession(ctx context.Context,
12861298
privacyFlags.Serialize(),
12871299
)
12881300
if err != nil {
1289-
return nil, fmt.Errorf("error registering session with "+
1290-
"autopilot server: %v", err)
1301+
return nil, fail(fmt.Errorf("error registering session with "+
1302+
"autopilot server: %v", err))
12911303
}
12921304

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

0 commit comments

Comments
 (0)