Issue #19473 has been reported by Eregon (Benoit Daloze).
----------------------------------------
Bug #19473: can't be called from trap context (ThreadError) is too limiting
https://bugs.ruby-lang.org/issues/19473
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
Simple reproducer:
```
$ ruby -ve 'm=Mutex.new; trap(:HUP) { m.synchronize { p :OK } }; Process.kill :HUP, Process.pid; sleep 0.1'
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-linux]
-e:1:in `synchronize': can't be called from trap context (ThreadError)
from -e:1:in `block in <main>'
from -e:1:in `kill'
from -e:1:in `<main>'
```
Expected behavior:
```
$ ruby -ve 'm=Mutex.new; trap(:HUP) { m.synchronize { p :OK } }; Process.kill :HUP, Process.pid; sleep 0.1'
truffleruby 22.3.1, like ruby 3.0.3, GraalVM CE Native [x86_64-linux]
:OK
$ ruby -ve 'm=Mutex.new; trap(:HUP) { m.synchronize { p :OK } }; Process.kill :HUP, Process.pid; sleep 0.1'
jruby 9.4.0.0 (3.1.0) 2022-11-23 95c0ec159f OpenJDK 64-Bit Server VM 17.0.6+10 on 17.0.6+10 +jit [x86_64-linux]
:OK
```
This exception is highly problematic, for instance it breaks `Timeout.timeout` in `trap`:
https://github.com/ruby/timeout/issues/17#issuecomment-1142035939
I suppose this behavior is because *sometimes* it's problematic to lock a Mutex in trap, e.g., if it's already locked by the main thread/fiber.
However, that's just one case, not all, so we should not raise an exception early like that.
There seems to be no valid reason to prevent *all* `Mutex#synchronize` in `trap`.
After all, if the Mutex for instance is only used in `trap`, it's well-defined AFAIK.
For instance a given trap handler does not seem executed concurrently:
```
$ ruby -ve 'trap(:HUP) { puts "in trap\n"+caller.join("\n")+"\n\n"; sleep 0.1 }; pid = Process.pid; Process.wait fork { 20.times { Process.kill :HUP, pid } }; sleep 1'
ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-linux]
in trap
-e:1:in `wait'
-e:1:in `<main>'
in trap
-e:1:in `wait'
-e:1:in `<main>'
in trap
-e:1:in `wait'
-e:1:in `<main>'
in trap
-e:1:in `wait'
-e:1:in `<main>'
in trap
-e:1:in `wait'
-e:1:in `<main>'
in trap
-e:1:in `wait'
-e:1:in `<main>'
```
And if the trap handler using the Mutex is never called while the Mutex is held by the main thread/fiber, there is also no problem.
--
https://bugs.ruby-lang.org/
Issue #20452 has been reported by Earlopain (A S).
----------------------------------------
Bug #20452: Ruby 3.3 on Alpine Linux results in a relatively shallow SystemStackError exception
https://bugs.ruby-lang.org/issues/20452
* Author: Earlopain (A S)
* Status: Open
* ruby -v: 3.3.1
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
This is a redo of https://bugs.ruby-lang.org/issues/14387, reported against a non-eol version. The same issue still applies on recent rubies, though I personally only have tested 3.3 and 3.2:
```rb
n = 100000
res = {}
1.upto(n).to_a.inject(res) do |r, i|
r[i] = {}
end
def f(x)
x.each_value { |v| f(v) }
end
f(res)
```
The patch from https://bugs.ruby-lang.org/issues/14387#note-13 still works, though as per https://bugs.ruby-lang.org/issues/14387#note-16 it can't be accepted as is.
With the patch applied:
```
(irb):8:in `block in f': stack level too deep (SystemStackError)
from (irb):8:in `each_value'
from (irb):8:in `f'
from (irb):8:in `block in f'
from (irb):8:in `each_value'
from (irb):8:in `f'
from (irb):8:in `block in f'
from (irb):8:in `each_value'
from (irb):8:in `f'
... 11549 levels...
from /usr/local/lib/ruby/gems/3.3.0/gems/irb-1.11.0/exe/irb:9:in `<top (required)>'
from /usr/local/bin/irb:25:in `load'
from /usr/local/bin/irb:25:in `<main>'
```
Without the patch:
```
(irb):8:in `each_value': stack level too deep (SystemStackError)
from (irb):8:in `f'
from (irb):8:in `block in f'
from (irb):8:in `each_value'
from (irb):8:in `f'
from (irb):8:in `block in f'
from (irb):8:in `each_value'
from (irb):8:in `f'
from (irb):8:in `block in f'
... 286 levels...
from /usr/local/lib/ruby/gems/3.3.0/gems/irb-1.11.0/exe/irb:9:in `<top (required)>'
from /usr/local/bin/irb:25:in `load'
from /usr/local/bin/irb:25:in `<main>'
```
To reproduce, I have removed lines 102-105 from https://github.com/docker-library/ruby/blob/f5753434bb23041dd9913bb7b650e7b…. Check out the previous ticket for more information, there are a few conversations about possible solutions.
--
https://bugs.ruby-lang.org/
Issue #20009 has been reported by ippachi (Kazuya Hatanaka).
----------------------------------------
Bug #20009: Marshal.load raises exception when load dumped class include non-ASCII
https://bugs.ruby-lang.org/issues/20009
* Author: ippachi (Kazuya Hatanaka)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin22]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
## Reproduction code
```ruby
class Cクラス; end
Marshal.load(Marshal.dump(Cクラス))
```
## Actual result
```
<internal:marshal>:34:in `load': undefined class/module C\xE3\x82\xAF\xE3\x83\xA9\xE3\x82\xB9 (ArgumentError)
from marshal.rb:2:in `<main>'
```
## Expected result
Returns `Cクラス`
## Impacted area
An exception is raised in Rails under the following conditions
* minitest is used with default settings
* Parallel execution with parallelize
* test class names contain non-ASCII characters
The default parallelization uses DRb, and Marshal is used inside DRb.
## Other
After trying various things, I thought I could fix it by making `rb_path_to_class` support strings containing non-ASCII characters, but I couldn't find anything more than that.
--
https://bugs.ruby-lang.org/
Issue #19154 has been reported by fxn (Xavier Noria).
----------------------------------------
Bug #19154: Specify require and autoload guarantees in ractors
https://bugs.ruby-lang.org/issues/19154
* Author: fxn (Xavier Noria)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.2.0preview3 (2022-11-27) [x86_64-darwin22]
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Given a file `c.rb`:
```ruby
class C
end
```
the following script:
```ruby
r1 = Ractor.new do
require './c.rb'
end
r2 = Ractor.new do
require './c.rb'
end
r1.take
r2.take
```
raises:
```
% ruby -v foo.rb
ruby 3.2.0preview3 (2022-11-27) [x86_64-darwin22]
foo.rb:1: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
#<Thread:0x000000010fee2928 run> terminated with exception (report_on_exception is true):
#<Thread:0x00000001102acfe0 run> terminated with exception (report_on_exception is true):
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
from foo.rb:6:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require'<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': : can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError) from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
from foo.rb:2:in `block in <main>'
from foo.rb:6:in `block in <main>'
<internal:ractor>:698:in `take': thrown by remote Ractor. (Ractor::RemoteError)
from foo.rb:9:in `<main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:164:in `ensure in require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
from <internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:167:in `require'
from foo.rb:2:in `block in <main>'
<internal:/Users/fxn/.rbenv/versions/3.2.0-preview3/lib/ruby/3.2.0+3/rubygems/core_ext/kernel_require.rb>:37:in `require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (Ractor::IsolationError)
from foo.rb:2:in `block in <main>'
```
Would it be possible to have documentation about their interaction?
This is important also to understand autoloading within ractors, since constant references may trigger `require` calls.
--
https://bugs.ruby-lang.org/
Issue #20105 has been reported by ioquatix (Samuel Williams).
----------------------------------------
Bug #20105: Introduce `IO::Stream` or something similar.
https://bugs.ruby-lang.org/issues/20105
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Assignee: ioquatix (Samuel Williams)
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Ruby's IO class has a general model for streaming IO, including some hidden classes like `IO::generic_readable` and `IO::generic_writable`.
As Ruby's core IO classes evolve, gems like `openssl` (see `OpenSSL::Buffering`) need to be updated to support changes to the interface.
As it stands, there are changes in `IO` which are not copied to `OpenSSL::Buffering`. I'd like to propose we introduce some shared interface for streams that is used by `IO`, `Socket`, and `OpenSSL` to start with. The general interface would be similar to `IO` and allow code like `OpenSSL` to avoid re-implementing the `IO` interface.
--
https://bugs.ruby-lang.org/
Issue #20346 has been reported by forthoney (Seong-Heon Jung).
----------------------------------------
Bug #20346: FiberScheduler.unblock not called by Thread#join when Thread body contains Ractor.take
https://bugs.ruby-lang.org/issues/20346
* Author: forthoney (Seong-Heon Jung)
* Status: Open
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
When using a `Ractor.take` inside a different thread, `Thread#join` on the thread running `Ractor.take` fails to call `FiberScheduler.unblock`. The below code can replicate this behavior
```ruby
require "async"
class RactorWrapper
def initialize
@ractor = Ractor.new do
Ractor.recv # Ractor doesn't start until explicitly told to
# Do some calculations
fib = ->(x) { x < 2 ? 1 : fib.call(x - 1) + fib.call(x - 2) }
fib.call(20)
end
end
def take_async
@ractor.send(nil)
Thread.new { @ractor.take }.join.value
end
end
Async do |task|
10000.times do |i|
task.async do
RactorWrapper.new.take_async
puts i
end
end
end
```
The above code deadlocks, and when we leave a debugging print statement inside of `Async`'s scheduler's `block` and `unblock` method, we can confirm that we only call `Scheduler.block`, and never `Scheduler.unblock`
--
https://bugs.ruby-lang.org/
Issue #20405 has been reported by nobu (Nobuyoshi Nakada).
----------------------------------------
Feature #20405: Inline comments
https://bugs.ruby-lang.org/issues/20405
* Author: nobu (Nobuyoshi Nakada)
* Status: Open
----------------------------------------
I propose a new inline comment syntax.
```ruby
p (| This is a comment (| and nested one |) /:|) (:|) #=> :|
```
--
https://bugs.ruby-lang.org/
Issue #20112 has been reported by ariasdiniz (Aria Diniz).
----------------------------------------
Bug #20112: Ractors not working properly in ruby 3.3.0
https://bugs.ruby-lang.org/issues/20112
* Author: ariasdiniz (Aria Diniz)
* Status: Open
* Priority: Normal
* ruby -v: 3.3.0
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I recently installed Ruby 3.3.0, and noticed that some of my scripts that use Ractors started to struggle with performance. After doing some benchmarks, I noticed that, while Ractors seem to be working well on Ruby 3.2.2, they're not working properly on 3.3.0.
I'm using Ubuntu 22.04.3 LTS
Here is the benchmark code:
``` ruby
# frozen_string_literal: true
require 'benchmark'
Ractor.new { :warmup } if defined?(Ractor)
Benchmark.bmbm do |x|
x.report("Thread: ") do
threads = []
8.times do |i|
threads << Thread.new do
20000000.times do |j|
((i * 20000000) + j)**2
end
end
end
threads.each(&:join)
end
x.report("Ractor: ") do
ractors = []
0..8.times do |i|
ractors << Ractor.new(i) do |k|
20000000.times do |j|
((k * 20000000) + j)**2
end
end
end
ractors.map(&:take)
end
end
```
Here is the results for Ruby 3.2.2:
Rehearsal --------------------------------------------
Thread: 7.666909 0.001091 7.668000 ( 7.675266)
Ractor: 19.318528 0.012017 19.330545 ( 2.505888)
---------------------------------- total: 26.998545sec
user system total real
Thread: 7.918141 0.004011 7.922152 ( 7.928772)
Ractor: 19.366414 0.003954 19.370368 ( 2.517993)
Here is the results for Ruby 3.3.0:
Rehearsal --------------------------------------------
Thread: 8.634152 0.010895 8.645047 ( 8.645104)
Ractor: 100.172179 0.035985 100.208164 ( 15.213245)
--------------------------------- total: 108.853211sec
user system total real
Thread: 9.451236 0.004002 9.455238 ( 9.460132)
Ractor: 118.463294 0.119942 118.583236 ( 18.462157)
--
https://bugs.ruby-lang.org/
Issue #19338 has been reported by luke-gru (Luke Gruber).
----------------------------------------
Bug #19338: Ruby hangs when defining new constant in ractor
https://bugs.ruby-lang.org/issues/19338
* Author: luke-gru (Luke Gruber)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
This code causes Ruby to hang:
``` ruby
rs = []
2.times do
rs << Ractor.new do
MYCONSTANT = 2
end
end
rs.each(&:take)
```
There is a problem when the warning is being outputted with multiple ractors. A thread is calling RB_VM_LOCK() while holding the VM lock in ractor.c (ractor_check_blocking())
If the code is changed to RB_VM_LOCK_ENTER() and RB_VM_LOCK_LEAVE() then it fixes it, but I don't know if there's a better way.
Thanks!
--
https://bugs.ruby-lang.org/
Issue #20165 has been reported by codekitchen (Brian Palmer).
----------------------------------------
Bug #20165: Ractors moving a Struct breaks beyond the first 3 fields
https://bugs.ruby-lang.org/issues/20165
* Author: codekitchen (Brian Palmer)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
Experimenting with Ractors on ruby 3.3.0, and I'm seeing a bug where if you move a struct between ractors, all but the first 3 fields are set to nil.
``` ruby
Foo = Struct.new(:a,:b,:c,:d,:e,:f)
r = Ractor.new {
foo = Foo[0,0,0,0,0,0]
p foo
Ractor.yield(foo, move: true)
}
p r.take
```
```
❯ ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
❯ ruby rbug.rb
rbug.rb:3: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues.
#<struct Foo a=0, b=0, c=0, d=0, e=0, f=0>
#<struct Foo a=0, b=0, c=0, d=nil, e=nil, f=nil>
```
This seems specific to moving, if I set `move: false` the struct makes it across OK.
--
https://bugs.ruby-lang.org/