Skip to content

Commit 7a16070

Browse files
Fix GC safety in rb_fiber_scheduler_blocking_operation_wait
Extract the raw operation pointer before rb_funcall so it is obtained while the GVL is held and no fiber switch has occurred yet. Place RB_GC_GUARD(blocking_operation) after the last implicit use of the VALUE — all accesses via the derived `operation` pointer — so the compiler cannot treat blocking_operation as dead before this point, keeping it reachable as a GC root through rb_funcall and through all subsequent uses of the raw pointer. See: socketry/io-event#172 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 276f0d9 commit 7a16070

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

scheduler.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,9 @@ VALUE rb_fiber_scheduler_blocking_operation_wait(VALUE scheduler, void* (*functi
11111111
operation->data2 = NULL;
11121112
operation->unblock_function = NULL;
11131113

1114+
// Ensure that the blocking operation remains visible until this point:
1115+
RB_GC_GUARD(blocking_operation);
1116+
11141117
// If the blocking operation was never executed, return Qundef to signal the caller to use rb_nogvl instead
11151118
if (current_status == RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED) {
11161119
return Qundef;

0 commit comments

Comments
 (0)