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

Don't panic if the duration is negative in try_get_or_insert #3413

Merged
merged 1 commit into from
Dec 20, 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
11 changes: 7 additions & 4 deletions packages/isrg/src/memory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ impl InMemoryCache {
let age = elapsed.num_seconds();
// The cache entry is out of date, so we need to remove it.
if let Some(invalidate_after) = self.invalidate_after {
if elapsed.to_std().unwrap() > invalidate_after {
tracing::trace!("memory cache out of date");
memory_cache.pop(route);
return Ok(None);
// If we can't convert to a std duration, the duration is negative and hasn't elapsed yet.
if let Ok(std_elapsed) = elapsed.to_std() {
if std_elapsed > invalidate_after {
tracing::trace!("memory cache out of date");
memory_cache.pop(route);
return Ok(None);
}
}
}

Expand Down
Loading