From c48c38ab8c6f0a1a747f6cc2eda20fdabad81df9 Mon Sep 17 00:00:00 2001 From: Stefan Reiter Date: Thu, 17 Jun 2021 11:02:32 +0200 Subject: [PATCH] async_lru_cache: fix handling of errors in fetch The future needs to be removed from the pending map in any case, even if it returned an error, else all upcoming calls to access this key will always return the same error. Signed-off-by: Stefan Reiter Signed-off-by: Wolfgang Bumiller --- src/tools/async_lru_cache.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/tools/async_lru_cache.rs b/src/tools/async_lru_cache.rs index cc385ec9..62e74fcd 100644 --- a/src/tools/async_lru_cache.rs +++ b/src/tools/async_lru_cache.rs @@ -65,15 +65,16 @@ impl AsyncL }; let result = result_fut.await; - match result { - Ok(Some(ref value)) if owner => { - // this call was the one initiating the request, put into LRU and remove from map - let mut maps = self.maps.lock().unwrap(); + + if owner { + // this call was the one initiating the request, put into LRU and remove from map + let mut maps = self.maps.lock().unwrap(); + if let Ok(Some(ref value)) = result { maps.0.insert(key, value.clone()); - maps.1.remove(&key); } - _ => {} + maps.1.remove(&key); } + result } }