Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get_children should not break supervision tree integrity #311

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions ractor/src/actor/supervision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ impl SupervisionTree {
/// from the supervision tree since the supervisor is shutting down
/// and can't deal with superivison events anyways
pub(crate) fn terminate_all_children(&self) {
let cells = self.get_children();
let mut guard = self.children.lock().unwrap();
let cells = guard.values().cloned().collect::<Vec<_>>();
guard.clear();
// drop the guard to not deadlock on double-link
drop(guard);
for cell in cells {
cell.terminate();
cell.clear_supervisor();
Expand Down Expand Up @@ -134,13 +138,10 @@ impl SupervisionTree {
}
}

/// Return all linked children
pub(crate) fn get_children(&self) -> Vec<ActorCell> {
let mut guard = self.children.lock().unwrap();
let cells = guard.iter().map(|(_, a)| a.clone()).collect::<Vec<_>>();
guard.clear();
// drop the guard to not deadlock on double-link
drop(guard);
cells
let guard = self.children.lock().unwrap();
guard.values().cloned().collect()
}

/// Send a notification to the supervisor.
Expand Down
3 changes: 3 additions & 0 deletions ractor/src/actor/tests/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,9 @@ async fn draining_children_will_shutdown_parent_too() {
// notify the parent (supervisor) and take that down too
supervisor_ref.drain_children();

// children were not unlinked by draining them (fixed from #310)
assert!(!supervisor_ref.get_children().is_empty());

// Wait for exit
s_handle.await.unwrap();
c_handle.await.unwrap();
Expand Down
Loading