-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Use a T_DATA for cross_ractor_require #13531
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
base: master
Are you sure you want to change the base?
Conversation
it should be problem with ractor local gc.
hmm, other ideas? |
static void | ||
cross_ractor_require_mark(void *ptr) | ||
{ | ||
struct cross_ractor_require *crr = (struct cross_ractor_require *)ptr; | ||
rb_gc_mark(crr->port); | ||
rb_gc_mark(crr->result); | ||
rb_gc_mark(crr->exception); | ||
rb_gc_mark(crr->feature); | ||
rb_gc_mark(crr->module); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use declarative marking for this instead? https://github.com/Shopify/ruby/blob/master/doc/extension.rdoc/#declaratively-markingcompacting-struct-references-
Previously rb_ractor_interrupt_exec would use an intermediate function to create a new thread with the actual target function, replacing the data being passed in with a piece of malloc memory holding the "next" function and the original data. Because of this, passing rb_interrupt_exec_flag_value_data to rb_ractor_interrupt_exec didn't have the intended effect of allowing data to be passed in and marked. This commit adds a rb_interrupt_exec_flag_new_thread flag, which both simplifies the implementation and allows the original data to be marked.
[Bug #21090] The struct was previously allocated on the stack, which could be freed if the Thread is terminated. Moving this to a T_DATA on the heap should mean this is no longer an issue. 1000.times { Ractor.new { th = Thread.new { require "rbconfig" }; Thread.pass }.take } Co-authored-by: Luke Gruber <luke.gruber@shopify.com>
cb5120c
to
750e603
Compare
750e603
to
fc54ae5
Compare
This comment has been minimized.
This comment has been minimized.
I made the new CRR object shareable. I also fixed the todo comment and make |
Fixes Bug #21090
The struct was previously allocated on the stack, which could be freed if the Thread is terminated. Moving this to a T_DATA on the heap should mean this is no longer an issue.
Previously this would segfault, due to accessing the Thread's memory after it was terminated (when the Ractor exits). Now it prints 1000 times:
The error comes from trying to send the result of the require back through the port. Maybe we could have a better error message, but that seems pretty reasonable to me given how much of an edge case this is.
cc @ko1 @luke-gru