From 3c6104b15b9341268a7bbd872f31dcddf85a3679 Mon Sep 17 00:00:00 2001 From: J-Loudet Date: Wed, 11 Sep 2024 16:11:26 +0200 Subject: [PATCH] fix(storage-manager): race condition on `latest_updates` structure (#1399) Signed-off-by: Julien Loudet --- .../src/replica/storage.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs index 8f51ddf9c5..956cd57f8d 100644 --- a/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs +++ b/plugins/zenoh-plugin-storage-manager/src/replica/storage.rs @@ -359,10 +359,9 @@ impl StorageService { // If the Storage was declared as only keeping the Latest value, we ensure that, for // each received Sample, it is indeed the Latest value that is processed. + let mut latest_updates_guard = self.latest_updates.lock().await; if self.capability.history == History::Latest { - if let Some(stored_timestamp) = - self.latest_updates.lock().await.get(&stripped_key) - { + if let Some(stored_timestamp) = latest_updates_guard.get(&stripped_key) { if sample_to_store_timestamp < *stored_timestamp { tracing::debug!( "Skipping Sample for < {:?} >, a Value with a more recent \ @@ -407,11 +406,9 @@ impl StorageService { // track of the Latest value, the timestamp is indeed more recent (it was // checked before being processed): we update our internal structure. if self.capability.history == History::Latest { - self.latest_updates - .lock() - .await - .insert(stripped_key, sample_to_store_timestamp); + latest_updates_guard.insert(stripped_key, sample_to_store_timestamp); } + drop(latest_updates_guard); if let Some(replication) = &self.replication { if let Err(e) = replication