From 01f90d4bf1a7d36fd7e916cecc0be3025bb32a39 Mon Sep 17 00:00:00 2001 From: yly Date: Sun, 19 Nov 2023 05:05:13 +0800 Subject: [PATCH] FIX: GC kicked off valid users --- src/main.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 8ad8ffe..fc6c556 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,6 +96,7 @@ async fn auth( let mut locked = state.session.lock().await; if locked.contains_key(&s) { // FIX, when accessed /auth with correct cookie, the cookie's expiration is delayed let Some(v) = locked.insert(s,Instant::now()+Duration::from_secs(SESSION_ACTIVE_TIME)) else { + tracing::info!("session:{} extended",session_token.value()); return StatusCode::UNAUTHORIZED; }; if Instant::now() < v { @@ -188,7 +189,8 @@ pub fn check_otp(key_from_db: String, user_input_otp: String) -> bool { async fn gc(state:Arc)->Result<(),String>{ let mut locked = state.session.lock().await; let current_time = Instant::now(); - locked.borrow_mut().retain(|_,v| *v < current_time); + tracing::info!("before gc ,active Sessions {:?}",locked); + locked.borrow_mut().retain(|_,v| *v > current_time); tracing::info!("gc fired,active Sessions {:?}",locked); Ok(()) }