@@ -7563,33 +7563,41 @@ impl NexusExternalApi for NexusExternalApiImpl {
75637563 let apictx = rqctx. context ( ) ;
75647564 let handler = async {
75657565 let nexus = & apictx. context . nexus ;
7566+ // this is unique among the hundreds of calls to this function in
7567+ // that we are not using ? to return early on error
75667568 let opctx =
75677569 crate :: context:: op_context_for_external_api ( & rqctx) . await ;
7568- let token = cookies. get ( session_cookie:: SESSION_COOKIE_COOKIE_NAME ) ;
7570+ let session_cookie =
7571+ cookies. get ( session_cookie:: SESSION_COOKIE_COOKIE_NAME ) ;
75697572
7573+ // Look up session and delete it if present. Noop on any errors.
7574+ // This is the ONE spot where we do the hard delete by token and we
7575+ // haven't already looked up the session by token. Looking up the
7576+ // token first works, but it would be nice to avoid it.
75707577 if let Ok ( opctx) = opctx {
7571- if let Some ( token) = token {
7572- // TODO: This is the ONE spot where we do the hard delete
7573- // by token and we haven't already looked up the session
7574- // by token. Looking up the token first works but it would
7575- // be nice to avoid it
7576-
7577- // look up session and delete it if present. noop on any errors
7578- let session = nexus
7579- . session_fetch ( & opctx, token. value ( ) . to_string ( ) )
7580- . await ;
7581- if let Ok ( session) = session {
7582- let session_id = session. console_session . id ( ) ;
7583- let _ =
7584- nexus. session_hard_delete ( & opctx, session_id) . await ;
7585- }
7578+ if let Some ( cookie) = session_cookie {
7579+ let token = cookie. value ( ) . to_string ( ) ;
7580+ match nexus. session_fetch ( & opctx, token) . await {
7581+ Ok ( session) => {
7582+ let id = session. console_session . id ( ) ;
7583+ // ? here because if this fails, we did not delete the
7584+ // session when we meant to
7585+ nexus. session_hard_delete ( & opctx, id) . await ?;
7586+ }
7587+ // blow up only on errors other than not found, because not
7588+ // found is fine: nothing to delete
7589+ Err ( Error :: ObjectNotFound { .. } ) => { } // noop
7590+ Err ( e) => return Err ( e. into ( ) ) ,
7591+ } ;
75867592 }
75877593 }
75887594
7589- // If user's session was already expired, they failed auth and their
7590- // session was automatically deleted by the auth scheme. If they have no
7591- // session (e.g., they cleared their cookies while sitting on the page)
7592- // they will also fail auth.
7595+ // If user's session was already expired, they fail auth and their
7596+ // session is automatically deleted by the auth scheme. If they
7597+ // have no session at all (because, e.g., they cleared their cookies
7598+ // while sitting on the page) they will also fail auth, but nothing
7599+ // is deleted and the above lookup by token fails (but doesn't early
7600+ // return).
75937601
75947602 // Even if the user failed auth, we don't want to send them back a 401
75957603 // like we would for a normal request. They are in fact logged out like
0 commit comments