Project

General

Profile

Actions

Bug #21504

open

[Ractor] Process.waitpid blocks ractor, new NT doesn't pick up other ractors

Added by luke-gru (Luke Gruber) about 7 hours ago. Updated about 7 hours ago.

Status:
Open
Assignee:
Target version:
-
[ruby-core:122683]

Description

The following code hangs when run with RUBY_MAX_CPU=2 make run:

Note: RUBY_MAX_CPU is set to 2 so that only 1 non-main ractor can run at once.

test.rb:

rs = []
2.times do |i|
  rs << Ractor.new(i) do |i|
    if i == 0
      io = IO.popen("ruby -e 'sleep'")
      Process.wait(io.pid) # block forever
    else
      sleep 1 # make sure first ractor blocks forever first
      $stderr.puts "Running r #{i}"
      100_000.times do
        [nil] * 1_000
      end
      $stderr.puts "done r #{i}"
    end
  end
end

while rs.size == 2
  r, obj = Ractor.select(*rs)
  rs.delete(r)
end

The timer thread should create a new NT to compensate for the dedicated task, and the new NT should be able to pick up the other runnable ractor.

In contrast, the following works fine:

rs = []
2.times do |i|
  rs << Ractor.new(i) do |i|
    if i == 0
      r, w = IO.pipe
      r.read(1) # block forever
    else
      sleep 1 # make sure first ractor blocks forever first
      $stderr.puts "Running r #{i}"
      100_000.times do
        [nil] * 1_000
      end
      $stderr.puts "done r #{i}"
    end
  end
end

while rs.size == 2
  r, obj = Ractor.select(*rs)
  rs.delete(r)
end

Updated by jhawthorn (John Hawthorn) about 7 hours ago

  • Assignee set to ractor
Actions

Also available in: Atom PDF

Like0
Like0