From a67ad37c6702b3f7cff9ad9d8120340a6ff053aa Mon Sep 17 00:00:00 2001 From: Leon Qadirie Date: Wed, 7 Feb 2024 14:40:28 +0100 Subject: [PATCH] Reduce race condition potential of `leave-*` functions --- ractor/src/pg/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ractor/src/pg/mod.rs b/ractor/src/pg/mod.rs index 1a463986..adf7fbd0 100644 --- a/ractor/src/pg/mod.rs +++ b/ractor/src/pg/mod.rs @@ -223,15 +223,15 @@ pub fn leave_scoped(scope: ScopeName, group: GroupName, actors: Vec) // if the scope and group tuple is empty, remove it if mut_ref.is_empty() { occupied_map.remove(); + } - // remove the group and possibly the scope from the monitor's index - if let Some(mut groups_in_scope) = monitor_idx { - groups_in_scope.retain(|group_name| group_name != &group); - if groups_in_scope.is_empty() { - // drop the `RefMut` to prevent a `DashMap` deadlock - drop(groups_in_scope); - monitor.index.remove(&scope); - } + // remove the group and possibly the scope from the monitor's index + if let Some(mut groups_in_scope) = monitor_idx { + groups_in_scope.retain(|group_name| group_name != &group); + if groups_in_scope.is_empty() { + // drop the `RefMut` to prevent a `DashMap` deadlock + drop(groups_in_scope); + monitor.index.remove(&scope); } }