Skip to content

Too many inner loops causes a crash #3

@fallwith

Description

@fallwith

Hi there. Thank you for all of your efforts with fiber_scheduler and the thought and planning that you've put into positioning it as a great default. I'm getting up to speed with Ruby 3 non-blocking fibers and have benefitted from your related writing.

I was playing around with using the fiber_scheduler gem and comparing it to other schedulers. I am using a non-block context (Fiber.set_scheduler). In an effort to have some test code do something that would take a little longer to complete, I added a 1_000.times loop wrapper and found that doing so causes a crash.

  • Using the code below I can reliably reproduce a crash with both Ruby 3.1.2 and 3.2.0-preview1.
  • If I remove the 1_000.times wrapper or lower the loop number to 92, the code works without crashing.
  • If I replace fiber_scheduler with async and FiberScheduler.new with Async::Scheduler.new, the code works without crashing.
  • As far as I can tell, #alive? ends up getting called on the wrong object, causing the crash. The object that method gets called on can change between runs.

Code to reproduce:

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'fiber_scheduler'

Thread.new do
  Fiber.set_scheduler FiberScheduler.new
  %w[apple banana grape lemon cherry lime].each do |fruit|
    Fiber.schedule do
      start_time = Time.now
      1_000.times do
        Math.exp(fruit.chars.sort.reverse.uniq.map(&:upcase).shuffle.sample.ord)
      end
      stop_time = Time.now
      puts "==> Elapsed #{stop_time - start_time} <== "
    end
  end
end.join

Error output:

~/.rubies/ruby-3.2.0-preview1/lib/ruby/gems/3.2.0+1/gems/fiber_scheduler-0.13.0/lib/fiber_scheduler.rb:122:in `select': undefined method `alive?' for [:blocking, #<RubyVM::AbstractSyntaxTree::Node:FALSE@47:21-47:26>]:Array (NoMethodError)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions