Bug #20288
closed`rb_fiber_scheduler_close` exceptions are not handled in `rb_fiber_scheduler_set`.
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:¶
- Define a custom fiber scheduler that raises an exception in its close method.
- Set the custom scheduler on a thread.
- Attempt to replace the custom scheduler with a different scheduler.
- 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.
Updated by ioquatix (Samuel Williams) about 1 year ago
Updated by ioquatix (Samuel Williams) about 1 year 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
Updated by k0kubun (Takashi Kokubun) 10 months ago
- Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONE
ruby_3_3 9cb804a2bd6eb43b67a716ccef6db400e47f29cf merged revision(s) 04729fe68dceddab045be7324e26c2bb15aa62c7.
Updated by nagachika (Tomoyuki Chikanaga) 8 months ago
- Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED, 3.3: DONE to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE, 3.3: DONE
ruby_3_2 89de66dbb0d8454c9d69faa331d6e35f8b315cce merged revision(s) 78d9fe69479d32214a52ad7291c3973f1b6b7f6f, 04729fe68dceddab045be7324e26c2bb15aa62c7.