You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The rust server checks all clients currently connected to determine if there are any stale connections or not.
May cause performance drops, but it's unlikely. Putting it here for future me.
The specific code I reference is
// Client timestamp update fairingpubstructClientTimestampUpdate;#[rocket::async_trait]implFairingforClientTimestampUpdate{fninfo(&self) -> Info{Info{name:"Update client timestamp",kind:Kind::Request}}asyncfnon_request(&self,request:&mutRequest<'_>, _:&mutData<'_>){let path_segments:Vec<String> = request.uri().path().split('/').map(|s| s.to_string()).collect();// Assuming that UUID is always the last segmentifletSome(uuid) = path_segments.last(){ifUuid::parse_str(uuid).is_ok(){// check if it is a valid uuidifletSome(state) = request.rocket().state::<TmsClients>(){with_clients_write(&state, |client_map| {ifletSome(client) = client_map.get_mut(uuid){
client.last_timestamp = std::time::SystemTime::now();}// Check all clients for stale connectionslet current_time = std::time::SystemTime::now();letmut stale_clients:Vec<String> = Vec::new();for(id, client)in client_map.iter(){ifletOk(duration) = current_time.duration_since(client.last_timestamp){if duration.as_secs() > (5*60){// 5 mins
stale_clients.push(id.to_string());}}}// remove oldest stale clients if there are more than 100let num_allowed_stale_clients = 100;if stale_clients.len() > num_allowed_stale_clients {
stale_clients.sort_by(|a, b| {
client_map[a].last_timestamp.cmp(&client_map[b].last_timestamp)});for i in0..(stale_clients.len() - num_allowed_stale_clients){let id = stale_clients[i].clone();
client_map.remove(&id);}}}).unwrap();}}}}}
The text was updated successfully, but these errors were encountered:
The rust server checks all clients currently connected to determine if there are any stale connections or not.
May cause performance drops, but it's unlikely. Putting it here for future me.
The specific code I reference is
The text was updated successfully, but these errors were encountered: