Project

General

Profile

Actions

Bug #17666

closed

Thread#join hangs when Fiber.set_scheduler is set

Added by arjunmdas (arjun das) about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-darwin19]
[ruby-core:102687]

Description

class MockScheduler
  def block(blocker, timeout = nil)
    byebug
  end

  def close
    byebug
  end

  def fiber(&block)
    byebug
    Fiber.new(blocking: false, &block).tap(&:resume)
  end

  def io_wait(io, events, timeout)
    byebug
  end

  def kernel_sleep(duration=nil)
    byebug
    Fiber.yield
  end

  def process_wait(pid, flags)
    byebug
  end

  def unblock(blocker, fiber)
    byebug
  end
end

Fiber.set_scheduler(MockScheduler.new)

t1 = Thread.new do
       p 'before'
       sleep 1
       p 'after'
     end

t1.join

Code hangs at this point.

Updated by arjunmdas (arjun das) about 1 month ago

  • Subject changed from Sleep in a thread hangs when Fiber.set_scheduler is set to Thread#join hangs when Fiber.set_scheduler is set
class MockScheduler
  def block(blocker, timeout = nil)
    byebug
  end

  def close
    byebug
  end

  def fiber(&block)
    byebug
    Fiber.new(blocking: false, &block).tap(&:resume)
  end

  def io_wait(io, events, timeout)
    byebug
  end

  def kernel_sleep(duration=nil)
    byebug
    Fiber.yield
  end

  def process_wait(pid, flags)
    byebug
  end

  def unblock(blocker, fiber)
    byebug
  end
end

Fiber.set_scheduler(MockScheduler.new)

t1 = Thread.new do
       p 'before'
       p 'after'
     end

t1.join

Code hangs a this point.

Updated by xtkoba (Tee KOBAYASHI) about 1 month ago

This issue seems already resolved in the latest development version. (I confirmed that it reproduces in 3.0.0p0 release version on x86_64-linux.)

Updated by arjunmdas (arjun das) about 1 month ago

Thanks a lot for confirming.
I will check the latest development version as well. Are you aware of any other tracking bug for this?

Updated by xtkoba (Tee KOBAYASHI) about 1 month ago

This issue seems fixed in 5f69a7f60467fa58c2f998daffab43e118bff36c. I'm not sure if there is a ticket here. There is a related PR in GitHub: https://github.com/ruby/ruby/pull/3945

Updated by arjunmdas (arjun das) about 1 month ago

Thanks again.

Just curious, how did you identify the right PR that fixed this?

Updated by xtkoba (Tee KOBAYASHI) about 1 month ago

arjunmdas (arjun das) I just searched the git log with the keyword "fiber". The PR number comes from the commit message.

Actions #7

Updated by jeremyevans0 (Jeremy Evans) about 1 month ago

  • Status changed from Open to Closed

Updated by arjunmdas (arjun das) about 1 month ago

xtkoba (Tee KOBAYASHI) - Re-verified in the latest development. It's fixed. Thanks for the update.
.

Actions

Also available in: Atom PDF