Skip to content

Commit d0e2242

Browse files
Reset runtime and preempted in rb_fiber_atfork
The child process inherits the parent's root fiber state at fork time. rb_fiber_atfork already reset quantum to the default but left runtime and preempted untouched. A child forked while a fiber had accumulated runtime or had preempted=1 would start with stale scheduling state, potentially triggering an immediate spurious preemption on the first back-edge check. Reset all three fields consistently, matching what rb_threadptr_root_fiber_setup does for a freshly created root fiber. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2f97734 commit d0e2242

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

cont.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3591,7 +3591,9 @@ rb_fiber_atfork(rb_thread_t *th)
35913591
}
35923592
th->root_fiber->prev = 0;
35933593
th->root_fiber->blocking = 1;
3594-
th->root_fiber->cont.saved_ec.quantum = RUBY_FIBER_QUANTUM_DEFAULT;
3594+
th->root_fiber->cont.saved_ec.runtime = 0;
3595+
th->root_fiber->cont.saved_ec.preempted = 0;
3596+
th->root_fiber->cont.saved_ec.quantum = RUBY_FIBER_QUANTUM_DEFAULT;
35953597
th->blocking = 1;
35963598
}
35973599
}

0 commit comments

Comments
 (0)