From 21fdecd219e7f25a415231e66cc9bbf710c36925 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Fri, 20 Dec 2024 14:02:07 -0600 Subject: [PATCH] Don't panic if the duration is negative in try_get_or_insert (#3413) --- packages/isrg/src/memory_cache.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/isrg/src/memory_cache.rs b/packages/isrg/src/memory_cache.rs index 533ba86b1d..1eeae1627d 100644 --- a/packages/isrg/src/memory_cache.rs +++ b/packages/isrg/src/memory_cache.rs @@ -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); + } } }