Skip to content

Commit

Permalink
add a cap for finished sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwicky committed Oct 17, 2024
1 parent eac43af commit d5bf107
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gateway/src/node/statistics/sessions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use time::{Date, Duration, OffsetDateTime};

use nym_statistics_common::events::SessionEvent;

const FINISHED_SESSIONS_CAP: usize = 1_000_000; //to be on the safe side of memory blowups until persistent storage

#[derive(PartialEq)]
enum SessionType {
Vpn,
Expand Down Expand Up @@ -132,7 +134,9 @@ impl SessionStatsHandler {
fn handle_session_stop(&mut self, stop_time: OffsetDateTime, client: DestinationAddressBytes) {
if let Some(session) = self.active_sessions.remove(&client) {
if let Some(finished_session) = session.end_at(stop_time) {
self.finished_sessions.push(finished_session);
if self.finished_sessions.len() < FINISHED_SESSIONS_CAP {
self.finished_sessions.push(finished_session);
}
}
}
}
Expand Down

0 comments on commit d5bf107

Please sign in to comment.