From d14b27669a02af79dd5da669c4127153fbdd6147 Mon Sep 17 00:00:00 2001 From: Adnan Zahir Date: Mon, 16 Nov 2026 21:19:58 +0700 Subject: [PATCH] fix: evict finished reconstitute sessions, keep the mTLS listener alive on accept errors, drop dead code Also removes OperatorActor.browser, unused since reconstitute targets are confined for every caller. Co-Authored-By: Claude Sonnet 5.5 --- crates/tessera-hub/src/admin.rs | 2 -- crates/tessera-hub/src/api/routes.rs | 19 ++++++++++++++++--- crates/tessera-hub/src/mtls.rs | 11 ++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/crates/tessera-hub/src/admin.rs b/crates/tessera-hub/src/admin.rs index b06798c..fb441ec 100644 --- a/crates/tessera-hub/src/admin.rs +++ b/crates/tessera-hub/src/admin.rs @@ -292,8 +292,6 @@ pub struct BrowserSession { pub id: uuid::Uuid, pub csrf: String, pub actor: String, - /// Read by per-user revoke and the OIDC login path (M3/M5). - #[allow(dead_code)] pub user_id: String, pub auth_method: String, /// May use the management API. A signed-in user without a grant is `false`. diff --git a/crates/tessera-hub/src/api/routes.rs b/crates/tessera-hub/src/api/routes.rs index e67af08..e7d156f 100644 --- a/crates/tessera-hub/src/api/routes.rs +++ b/crates/tessera-hub/src/api/routes.rs @@ -251,7 +251,6 @@ struct ReconstituteStartResponse { pub(super) struct OperatorActor { /// Display only. Never record this as "who did it": an IdP can call a user anything. pub(super) name: String, - pub(super) browser: bool, pub(super) principal: Principal, pub(super) subject: Subject, pub(super) request_id: Uuid, @@ -318,7 +317,6 @@ fn authenticate_inner( ) -> Result { let configured_admin = |name: &str, principal: Principal| OperatorActor { name: name.into(), - browser: false, principal, subject: Subject { user_id: None, @@ -351,7 +349,6 @@ fn authenticate_inner( principal: session.principal(), subject: session.subject(), name: session.actor, - browser: true, request_id, }); } @@ -860,6 +857,7 @@ async fn start_reconstitute( let mut map = state_bg.reconstitute_sessions.write().await; if let Some(s) = map.get_mut(&session_id) { if s.state == ReconstituteState::Aborted { + evict_reconstitute_later(&state_bg, session_id); return; } s.seconds_remaining = remaining; @@ -873,6 +871,7 @@ async fn start_reconstitute( return; }; if s.state == ReconstituteState::Aborted { + evict_reconstitute_later(&state_bg, session_id); return; } s.state = ReconstituteState::Restoring; @@ -891,6 +890,7 @@ async fn start_reconstitute( .db .audit("reconstitute.done", &format!("session={session_id}")) .await; + evict_reconstitute_later(&state_bg, session_id); }); Ok(Json(ReconstituteStartResponse { @@ -899,6 +899,19 @@ async fn start_reconstitute( })) } +/// How long a finished restore session stays readable before its entry is dropped. +const RECONSTITUTE_RETAIN: std::time::Duration = std::time::Duration::from_secs(3600); + +/// Drops a finished session from the in-memory map after `RECONSTITUTE_RETAIN`, so the map does +/// not grow for as long as the hub runs. +fn evict_reconstitute_later(state: &HubState, id: Uuid) { + let state = state.clone(); + tokio::spawn(async move { + tokio::time::sleep(RECONSTITUTE_RETAIN).await; + state.reconstitute_sessions.write().await.remove(&id); + }); +} + fn browser_export_path( state: &HubState, requested: &str, diff --git a/crates/tessera-hub/src/mtls.rs b/crates/tessera-hub/src/mtls.rs index ac9dda6..bf79818 100644 --- a/crates/tessera-hub/src/mtls.rs +++ b/crates/tessera-hub/src/mtls.rs @@ -75,7 +75,16 @@ pub async fn serve(mtls: WormholeMtls, app: Router) -> Result<()> { mtls.listen ); loop { - let (tcp, peer) = listener.accept().await.context("accept wormhole mTLS")?; + let (tcp, peer) = match listener.accept().await { + Ok(accepted) => accepted, + Err(error) => { + // Out of file descriptors, an aborted handshake and the like pass; stopping the + // listener would end every Outpost's connection until a restart. + tracing::warn!(%error, "wormhole mTLS accept failed; continuing"); + tokio::time::sleep(std::time::Duration::from_millis(100)).await; + continue; + } + }; let acceptor = acceptor.clone(); let app = app.clone(); tokio::spawn(async move {