Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove code that could potentially panic #3343

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions utils/actix_utils/src/deadline_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ impl DeadlineChecker {

fn on_deadline_elapsed(&mut self, ctx: &mut Context<Self>, deadline: DateTime<Utc>) {
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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -165,11 +170,7 @@ impl Handler<TrackDeadline> for DeadlineChecker {
type Result = ();

fn handle(&mut self, msg: TrackDeadline, ctx: &mut Context<Self>) -> 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).
Expand Down
Loading