From 30d8e3783cea9ff4250d8bbc24cbd3daa1f1a662 Mon Sep 17 00:00:00 2001 From: Alden Hu Date: Fri, 20 Sep 2024 11:49:22 -0700 Subject: [PATCH] Fix potential deadlock in state_key::Entry::drop (#14670) (cherry picked from commit 8eb8b52cc67d2b405c2d5c16ca98f3fa18db8797) --- types/src/state_store/state_key/registry.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/src/state_store/state_key/registry.rs b/types/src/state_store/state_key/registry.rs index 1fad8c4d90a15..c56577eda6653 100644 --- a/types/src/state_store/state_key/registry.rs +++ b/types/src/state_store/state_key/registry.rs @@ -152,13 +152,13 @@ where let mut locked = self.inner.write(); if let Some(map2) = locked.get_mut(key1) { if let Some(entry) = map2.get(key2) { - if entry.upgrade().is_none() { + if entry.strong_count() == 0 { map2.remove(key2); + if map2.is_empty() { + locked.remove(key1); + } } } - if map2.is_empty() { - locked.remove(key1); - } } }