Skip to content

(rebase) Ractor.make_shareable(proc_obj) makes inner structure shareable #12977

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

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

jhawthorn
Copy link
Member

@jhawthorn jhawthorn commented Mar 24, 2025

This is a rebase of #7182 with one tiny fix (not setting RUBY_FL_SHAREABLE) and I've added some additional tests

This PR adjusts Ractor.make_shareable to be more strict, and ensure all reachable objects from it are shareable (including ivars, Methods, etc)

luke-gru and others added 2 commits March 24, 2025 16:01
Proc objects are now traversed like other objects when making them
shareable.

Fixes [Bug #19372]
Fixes [Bug #19374]
Copy link

launchable-app bot commented Mar 24, 2025

All Tests passed!

✖️no tests failed ✔️61702 tests passed(1 flake)

@@ -1415,7 +1415,7 @@ rb_proc_ractor_make_shareable(VALUE self)
proc->is_isolated = TRUE;
}

FL_SET_RAW(self, RUBY_FL_SHAREABLE);
rb_obj_freeze(self);
Copy link
Contributor

@ko1 ko1 Mar 25, 2025

Choose a reason for hiding this comment

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

does it mark shareable flag on a Proc later?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does after traversing through the objects as part of rb_ractor_make_shareable. Setting it here before was allowing unfrozen objects to leak through.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok, mark_shareable will set.
Strictly speaking the Proc is not needed to be frozen, but okay.
no problem to merge.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we need to freeze to prevent instance variables from being set after it's made shareable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes it is safer. But for example Ractor objects are shareable but not frozen. The instance variables can be accessed only from main ractor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah! I see, thank you. I didn't see that behaviour in generic_ivtbl

@jhawthorn jhawthorn merged commit 46ee73f into ruby:master Mar 26, 2025
76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants