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

Conversation

kanru
Copy link
Contributor

@kanru kanru commented Jan 6, 2025

This fixes #310

Please suggest where and what tests I can add.

Copy link
Owner

@slawlor slawlor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not add a take functionality and just fix the bug in get_children clearing the collection

@@ -134,15 +134,21 @@ impl SupervisionTree {
}
}

pub(crate) fn get_children(&self) -> Vec<ActorCell> {
pub(crate) fn take_children(&self) -> Vec<ActorCell> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need a take method anywhere, the supervision tree should only be modified upon link/unlink. This should be as easy as just replacing the functionality inside with the non-clearing version, and updating a test case to make sure that the supervision tree isn't modified.

#310 is indeed a bug, and fixing it vs adding a new API like this is better for footgun safety.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some kind of clearing is still required. Initially I just removed the clear() but then the double-link test run out of stack. I realized if we don't clear the children list after unlink, we can run into mutual recursion in the double-link scenario. So instead of calling clear() everywhere I created the take method.

@slawlor
Copy link
Owner

slawlor commented Jan 6, 2025

Check out this commit. Feel free to pull it on top and update your PR

62efc43

@kanru kanru force-pushed the fix-ractor-get-children branch from 8b061c4 to 62efc43 Compare January 6, 2025 23:53
Copy link
Owner

@slawlor slawlor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

Copy link

codecov bot commented Jan 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.07%. Comparing base (1ae5d86) to head (62efc43).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #311      +/-   ##
==========================================
+ Coverage   82.04%   82.07%   +0.02%     
==========================================
  Files          61       61              
  Lines       12182    12183       +1     
==========================================
+ Hits         9995     9999       +4     
+ Misses       2187     2184       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@slawlor slawlor merged commit f45cdd2 into slawlor:main Jan 7, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ActorRef::get_children() clears children record from supervision tree
2 participants