Skip to content

Fix Fiber.schedule inside a non-blocking Fiber - #9604

Merged
headius merged 2 commits into
jruby:masterfrom
sampokuokkanen:fix-fiber-schedule-owning-thread
Aug 24, 2026
Merged

headius merged 2 commits into
jruby:masterfrom
sampokuokkanen:fix-fiber-schedule-owning-thread

Conversation

@sampokuokkanen

@sampokuokkanen sampokuokkanen commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

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!:

  • Fiber.schedule when a scheduler is set can be called from inside a non-blocking Fiber
  • Fiber.schedule when a scheduler is set uses the scheduler of the Thread owning the Fiber it is called from
  • Fiber.schedule when a scheduler is set runs the block in a Fiber which sees the scheduler as its current scheduler

(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)

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).
@headius

headius commented Aug 23, 2026

Copy link
Copy Markdown
Member

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.

@headius

headius commented Aug 23, 2026

Copy link
Copy Markdown
Member

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).

@sampokuokkanen

sampokuokkanen commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, I see that you already merged master, do you still want me to rebase?
@eregon told me that this (on truffleruby side here) is the correct way of doing things, since if the test files are identical the git merge will not conflict and we get the tests passing right away.

Most of the tests are passing now too, great! Thanks about that too.

@eregon

eregon commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

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.
There can even be further tweaks to the specs here, just needs to be a different commit so it applies cleanly.

@headius

headius commented Aug 24, 2026

Copy link
Copy Markdown
Member

@sampokuokkanen Nope we're all good here!

@eregon Thanks for clarifying!

@headius
headius merged commit 49b1e84 into jruby:master Aug 24, 2026
133 of 134 checks passed
@headius headius added this to the JRuby 10.1.2.0 milestone Aug 24, 2026
sampokuokkanen added a commit to sampokuokkanen/jruby that referenced this pull request Aug 26, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants