Fix Fiber.schedule inside a non-blocking Fiber - #9604
Conversation
Fiber.schedule looked up the scheduler on the Fiber's carrier thread rather than the Thread that owns it, so calling it from inside a non-blocking Fiber raised "No scheduler is available!". Use getFiberCurrentThread(), like Fiber.scheduler and MRI's rb_fiber_s_schedule. Specs come from ruby/spec#1388 (merged) and three of the six fail without this. One is tagged for a separate blocking-count bug (passes when run in isolation but fails when run with other fiber tests).
|
Nice simple fix and I appreciate the extra work getting the specs in place! The specs are periodically merged so I'd like to hear from @eregon or @andrykonchin that it's okay for us to also pull them in this way. The failures are not your fault and are due to a bad merge of an unrelated fix. |
|
The bad spec has been fixed on master; you can rebase if you get a chance, but it will be fine to merge either way (assuming the spec updates are ok). |
|
Thanks, I see that you already merged master, do you still want me to rebase? Most of the tests are passing now too, great! Thanks about that too. |
|
Yep, just to confirm it's fine to copy files over if they don't conflict, i.e. if they are copied as-is in a commit. |
|
@sampokuokkanen Nope we're all good here! @eregon Thanks for clarifying! |
Fiber.current_scheduler reads the Thread's blocking count, and it drifted both ways: Fiber#resume decremented a target that exchangeWithFiber had already decremented, and the hand-back was counted twice. Account like MRI's fiber_switch instead, where each Fiber adjusts only for itself. Adds core/fiber/current_scheduler_spec.rb from ruby/spec#1388 and drops the tag added in jruby#9604. Also adds additional root Fiber specs from ruby/spec#1390.
Fiber.schedule looked up the scheduler on the Fiber's carrier thread rather than the Thread that owns it, so calling it from inside a non-blocking Fiber raised "No scheduler is available!". Use getFiberCurrentThread(), like Fiber.scheduler and MRI's rb_fiber_s_schedule.
Specs come from ruby/spec#1388 (merged) and three of the six fail without this. One is tagged for a separate blocking-count bug (passes when run in isolation but fails when run with other fiber tests).
On master the following tests fail with
RuntimeError: No scheduler is available!:(The last one is the one that fails on this branch too when run with other fiber tests but passes when you just run
spec/ruby/core/fiber/schedule_spec.rb)