diff --git a/utils/actix_utils/src/deadline_checker.rs b/utils/actix_utils/src/deadline_checker.rs index a737be189..a386ecd4b 100644 --- a/utils/actix_utils/src/deadline_checker.rs +++ b/utils/actix_utils/src/deadline_checker.rs @@ -97,7 +97,12 @@ impl DeadlineChecker { fn on_deadline_elapsed(&mut self, ctx: &mut Context, deadline: DateTime) { let now = Utc::now(); - assert!(now >= deadline); + if now < deadline { + log::warn!( + "Programming error: Deadline didn't really elapse: {now} < {deadline}.\ + This was assert! in previous version, which could cause DeadlineChecker's death." + ); + } let elapsed = self.drain_elapsed(now); @@ -133,7 +138,7 @@ impl DeadlineChecker { elapsed.sort_by(|dead1, dead2| dead1.deadline.cmp(&dead2.deadline)); - // Remove Agreements with empty lists. Otherwise no longer needed Agreements + // Remove Agreements with empty lists. Otherwise, no longer needed Agreements // would remain in HashMap for always. self.deadlines = self .deadlines @@ -165,11 +170,7 @@ impl Handler for DeadlineChecker { type Result = (); fn handle(&mut self, msg: TrackDeadline, ctx: &mut Context) -> Self::Result { - if self.deadlines.get(&msg.category).is_none() { - self.deadlines.insert(msg.category.to_string(), vec![]); - } - - let deadlines = self.deadlines.get_mut(&msg.category).unwrap(); + let deadlines = self.deadlines.entry(msg.category.clone()).or_default(); let idx = match deadlines.binary_search_by(|element| element.deadline.cmp(&msg.deadline)) { // Element with this deadline existed. We add new element behind it (order shouldn't matter since timestamps // are the same, but it's better to keep order of calls to `track_deadline` function).