FIX: GC kicked off valid users

This commit is contained in:
yly 2023-11-19 05:05:13 +08:00
parent 600a29a77d
commit 01f90d4bf1

View File

@ -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<ServerState>)->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(())
}