Project

General

Profile

Actions

Bug #20288

closed

`rb_fiber_scheduler_close` exceptions are not handled in `rb_fiber_scheduler_set`.

Added by ioquatix (Samuel Williams) 2 months ago. Updated 2 months ago.


Description

The code responsible for setting a new scheduler on a thread does not properly handle exceptions raised by rb_fiber_scheduler_close. If rb_fiber_scheduler_close raised an exception, the assignment thread->scheduler = scheduler would not be executed. This leaves the thread in an undefined state because it might still hold a reference to the old scheduler, which was supposed to be closed and replaced.

Steps to Reproduce:

  1. Define a custom fiber scheduler that raises an exception in its close method.
  2. Set the custom scheduler on a thread.
  3. Attempt to replace the custom scheduler with a different scheduler.
  4. Observe that if the close method of the original scheduler raises an exception, the thread's scheduler reference is not updated.

Proposed Fix:

The use of rb_ensure can be introduced to wrap the call to rb_fiber_scheduler_close to ensure that, regardless of whether an exception is raised, thread->scheduler is set to Qnil, and then thread->scheduler = scheduler is safely executed to update the thread's scheduler reference.

Actions #2

Updated by ioquatix (Samuel Williams) 2 months ago

  • Status changed from Open to Closed
  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED
Actions

Also available in: Atom PDF

Like0
Like0Like0