Skip to content

Commit c13fe54

Browse files
committed
Downgrade rb_ractor_make_shareable to a warning under check_isolation
Etienne's reference-chain refactor (5fd43a3) moved the raise out of the per-object check callback and into rb_ractor_make_shareable itself, where it builds the exception locally and rb_exc_raise's directly. That bypassed rb_ractor_isolation_violation, so under Ractor.check_isolation a non-shareable Proc passed to Ractor.make_shareable was crashing again instead of warning. Restore the downgrade by branching on rb_thread_ractor_isolation_check_p inside rb_ractor_make_shareable: in check mode, format the exception's message together with the chain and emit a :ractor_isolation warning; otherwise attach the chain to @reference_chain and rb_exc_raise as before. The chain is appended inline in the warning message because there is no exception object to hang @reference_chain off of. This keeps the chain visible to anyone reading stderr without inventing a parallel warning-with-attached-data API.
1 parent 874a423 commit c13fe54

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

ractor.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,17 +1656,26 @@ rb_ractor_make_shareable(VALUE obj)
16561656
VALUE chain = Qnil;
16571657
VALUE exception = Qfalse;
16581658
if (rb_obj_traverse(obj, make_shareable_check_shareable, null_leave, mark_shareable, &chain, &exception)) {
1659-
if (exception) {
1659+
if (!exception) {
1660+
exception = rb_exc_new3(rb_eRactorError, rb_sprintf("can not make shareable object for %+"PRIsVALUE, obj));
1661+
}
1662+
// In Ractor.check_isolation mode downgrade to a :ractor_isolation
1663+
// warning (with the chain inlined) so the sweep can keep going.
1664+
// Outside that mode, attach the chain to @reference_chain and raise
1665+
// exactly as before.
1666+
if (rb_thread_ractor_isolation_check_p()) {
1667+
VALUE message = rb_obj_as_string(rb_funcall(exception, rb_intern("message"), 0));
1668+
if (!NIL_P(chain)) {
1669+
rb_str_append(message, chain);
1670+
}
1671+
rb_category_warn(RB_WARN_CATEGORY_RACTOR_ISOLATION, "%s", StringValueCStr(message));
1672+
}
1673+
else {
16601674
if (!NIL_P(chain)) {
16611675
rb_ivar_set(exception, id_reference_chain, chain);
16621676
}
16631677
rb_exc_raise(exception);
16641678
}
1665-
exception = rb_exc_new3(rb_eRactorError, rb_sprintf("can not make shareable object for %+"PRIsVALUE, obj));
1666-
if (!NIL_P(chain)) {
1667-
rb_ivar_set(exception, id_reference_chain, chain);
1668-
}
1669-
rb_exc_raise(exception);
16701679
}
16711680
RB_GC_GUARD(chain);
16721681
RB_GC_GUARD(exception);

0 commit comments

Comments
 (0)