Actions
Bug #20288
closed`rb_fiber_scheduler_close` exceptions are not handled in `rb_fiber_scheduler_set`.
Bug #20288:
`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.
Actions