Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many inner loops causes a crash #3

Open
fallwith opened this issue May 24, 2022 · 1 comment
Open

Too many inner loops causes a crash #3

fallwith opened this issue May 24, 2022 · 1 comment

Comments

@fallwith
Copy link

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)
@bruno-
Copy link
Owner

bruno- commented May 24, 2022

Hi,

I can reproduce this problem. I'll take a look!

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

No branches or pull requests

2 participants