Skip to content

Commit 43b76c6

Browse files
committed
ignore confirming belonging while finrializer
A finalizer registerred in Ractor A can be invoked in B. ```ruby require "tempfile" r = Ractor.new{ 10_000.times{|i| Tempfile.new(["file_to_require_from_ractor#{i}", ".rb"]) } } sleep 0.1 ``` For example, above script makes tempfiles which have finalizers on Ractor r, but at the end of the process, main Ractor will invoke finalizers and it violates belonging check. This patch just ignore the belonging check to avoid CI failure. Of course it violates Ractor's isolation and wrong workaround. This issue will be solved with Ractor local GC.
1 parent 3246bbd commit 43b76c6

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

gc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ rb_gc_run_obj_finalizer(VALUE objid, long count, VALUE (*callback)(long i, void
288288
saved.finished = 0;
289289
saved.final = Qundef;
290290

291+
rb_ractor_ignore_belonging(true);
291292
EC_PUSH_TAG(ec);
292293
enum ruby_tag_type state = EC_EXEC_TAG();
293294
if (state != TAG_NONE) {
@@ -306,6 +307,7 @@ rb_gc_run_obj_finalizer(VALUE objid, long count, VALUE (*callback)(long i, void
306307
rb_check_funcall(saved.final, idCall, 1, &objid);
307308
}
308309
EC_POP_TAG();
310+
rb_ractor_ignore_belonging(false);
309311
#undef RESTORE_FINALIZER
310312
}
311313

ractor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ static VALUE rb_cRactorMovedObject;
3333

3434
static void vm_ractor_blocking_cnt_inc(rb_vm_t *vm, rb_ractor_t *r, const char *file, int line);
3535

36+
37+
#if RACTOR_CHECK_MODE > 0
38+
bool ractor_ignore_belonging = false;
39+
#endif
40+
3641
// Ractor locking
3742

3843
static void

ractor_core.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,13 @@ rb_ractor_belonging(VALUE obj)
266266
}
267267
}
268268

269+
extern bool ractor_ignore_belonging;
270+
269271
static inline VALUE
270272
rb_ractor_confirm_belonging(VALUE obj)
271273
{
274+
if (ractor_ignore_belonging) return obj;
275+
272276
uint32_t id = rb_ractor_belonging(obj);
273277

274278
if (id == 0) {
@@ -288,6 +292,14 @@ rb_ractor_confirm_belonging(VALUE obj)
288292
}
289293
return obj;
290294
}
295+
296+
static inline void
297+
rb_ractor_ignore_belonging(bool flag)
298+
{
299+
ractor_ignore_belonging = flag;
300+
}
301+
291302
#else
292303
#define rb_ractor_confirm_belonging(obj) obj
304+
#define rb_ractor_ignore_belonging(flag) (0)
293305
#endif

0 commit comments

Comments
 (0)