Skip to content

Commit 495cea7

Browse files
committed
Show reference chain of constants for Ractor::IsolationError
1 parent 5eb48d5 commit 495cea7

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

variable.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,8 +3340,10 @@ rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility)
33403340
VALUE c = rb_const_search(klass, id, exclude, recurse, visibility);
33413341
if (!UNDEF_P(c)) {
33423342
if (UNLIKELY(!rb_ractor_main_p())) {
3343-
if (!rb_ractor_shareable_p(c)) {
3344-
rb_raise(rb_eRactorIsolationError, "can not access non-shareable objects in constant %"PRIsVALUE"::%s by non-main Ractor.", rb_class_path(klass), rb_id2name(id));
3343+
VALUE chain = rb_ary_new();
3344+
if (!rb_ractor_shareable_p_continue(c, chain)) {
3345+
rb_raise(rb_eRactorIsolationError, "can not access non-shareable objects in constant %"PRIsVALUE"::%s by non-main Ractor.\n"\
3346+
"Reference chain: %"PRIsVALUE, rb_class_path(klass), rb_id2name(id), chain);
33453347
}
33463348
}
33473349
return c;

vm_insnhelper.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,11 @@ vm_get_ev_const(rb_execution_context_t *ec, VALUE orig_klass, ID id, bool allow_
11431143
}
11441144
else {
11451145
if (UNLIKELY(!rb_ractor_main_p())) {
1146-
if (!rb_ractor_shareable_p(val)) {
1146+
VALUE chain = rb_ary_new();
1147+
if (!rb_ractor_shareable_p_continue(val, chain)) {
11471148
rb_raise(rb_eRactorIsolationError,
1148-
"can not access non-shareable objects in constant %"PRIsVALUE"::%s by non-main ractor.", rb_class_path(klass), rb_id2name(id));
1149+
"can not access non-shareable objects in constant %"PRIsVALUE"::%s by non-main ractor.\n"\
1150+
"Reference chain: %"PRIsVALUE, rb_class_path(klass), rb_id2name(id), chain);
11491151
}
11501152
}
11511153
return val;

0 commit comments

Comments
 (0)