Skip to content

Commit

Permalink
Fix potential deadlock in state_key::Entry::drop
Browse files Browse the repository at this point in the history
If before Entry::drop() calls Registry::maybe_remove, the weak ref under
the same key1 and key2 is replaced, Entry::drop can be called
recursively resulting in a deadlock. The crux is we try to see if the
entry has been replaced by trying to upgrading it to a strong ref, and
it possible that the upgrade is successful and the result becomes a only
ref to the new entry.

This tries to fix it by determining the same thing by seeing if
Weak::strong_count() is 0 instead of upgrading the weak ref.
  • Loading branch information
msmouse committed Sep 18, 2024
1 parent 09ce976 commit d14009e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion types/src/state_store/state_key/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ 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);
}
}
Expand Down

0 comments on commit d14009e

Please sign in to comment.