CARVIEW |
Select Language
HTTP/2 200
x-amz-id-2: 68Wf4WzWCBwY08GfJgwFXrNulep/xc+MR5OQeQnjcOf9uzwCONvDt2h7qcM8dZZwnBDXaNaAQg6v5h1Ue45nwjzgk5ysfdxKuiHsm3UyYHE=
x-amz-request-id: TFC1YRS49FEMVBKD
last-modified: Thu, 05 Jun 2025 04:32:00 GMT
etag: "16d14b958eea2c9540a4246f18126922"
x-amz-server-side-encryption: AES256
server: AmazonS3
content-encoding: gzip
via: 1.1 varnish, 1.1 varnish
content-type: text/plain; charset=utf-8
accept-ranges: bytes
age: 0
date: Wed, 23 Jul 2025 20:21:24 GMT
x-served-by: cache-tyo11968-TYO, cache-bom-vanm7210078-BOM
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1753302084.267993,VS0,VE330
vary: Accept-Encoding
content-length: 1391
From: "arino.tamada via ruby-core"
Date: 2025-06-05T04:21:56+00:00
Subject: [ruby-core:122417] [Ruby Bug#21398] Ractor.select hangs when multiple threads submit heavy jobs concurrently
Issue #21398 has been reported by arino.tamada (������ ������).
----------------------------------------
Bug #21398: Ractor.select hangs when multiple threads submit heavy jobs concurrently
https://bugs.ruby-lang.org/issues/21398
* Author: arino.tamada (������ ������)
* Status: Open
* ruby -v: ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +PRISM [arm64-darwin23]
* Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN
----------------------------------------
When multiple threads run heavy Ractor-based jobs at the same time, `Ractor.select(*workers)` can hang indefinitely without any crash, exception, or deadlock being reported.
This issue does not occur when only one thread is running similar jobs ��� the hang happens only when four or more threads submit large jobs concurrently to a shared Ractor pipeline.
### Steps to Reproduce
Run the script below in Ruby 3.4.2 or later.
In some runs, one or more threads will hang forever at Ractor.select.
The issue reproduces more easily on machines with multiple cores and sufficient memory.
### Expected Behavior
All calls to Ractor.select(*workers) should return when any worker Ractor yields a result. All jobs should complete.
### Actual Behavior
- In some runs (especially with multiple threads), `Ractor.select` hangs and never returns.
- There is no crash or exception; the process remains alive but blocked.
- All Ractors and threads are created and started correctly.
- This behavior does not occur when only one thread performs the same job sequentially.
- It appears that `Ractor.select` does not always behave reliably under concurrent multithreaded usage with heavy Ractor pipelines.
Reproducible Example:
```ruby
THREADS = 4
JOBS_PER_THREAD = 10
ARRAY_SIZE = 10_000
def ractor_job(job_count, array_size)
pipe = Ractor.new do
loop { Ractor.yield Ractor.receive }
end
workers = (1..4).map do
Ractor.new(pipe) do |pipe|
while job = pipe.take
result = job.map { |x| x * 2 }.sum
Ractor.yield result
end
end
end
jobs = Array.new(job_count) { Array.new(array_size) { rand(1000) } }
jobs.each { |job| pipe.send(job) }
results = []
jobs.size.times do
puts "Waiting for results..."
_ractor, result = Ractor.select(*workers)
puts "Received result: #{result}"
results << result
end
results
end
threads = []
THREADS.times do
threads << Thread.new do
ractor_job(JOBS_PER_THREAD, ARRAY_SIZE)
end
end
threads.each(&:join)
puts "All threads finished."
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/