Actions
Bug #21941
openLocal variable becomes nil when YJIT enabled mid-method with fork/signal/ensure
Bug #21941:
Local variable becomes nil when YJIT enabled mid-method with fork/signal/ensure
Description
The following code results in the read local variable becoming nil, even though it is never reassigned:
def run
fork_safe = ->(t) { t }
RubyVM::YJIT.enable
read, wakeup = IO.pipe
Signal.trap("SIGCHLD") { wakeup.write("!") }
begin
while true
begin
fork { exit }
next if read.wait_readable
rescue Interrupt
end
end
ensure
end
end
run
Error:
repro.rb:13:in 'Object#run': undefined method 'wait_readable' for nil (NoMethodError)
next if read.wait_readable
^^^^^^^^^^^^^^
from repro.rb:21:in '<main>'
See also:
https://github.com/puma/puma/issues/3620
https://github.com/Shopify/ruby/issues/625
Updated by byroot (Jean Boussier) about 12 hours ago
- Assignee set to jit
- Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.2: DONTNEED, 3.3: DONTNEED, 3.4: REQUIRED, 4.0: REQUIRED
Reduced even further:
def run
fork_safe = ->(t) { t }
RubyVM::YJIT.enable
read, wakeup = IO.pipe
wakeup.write("!")
begin
while true
begin
next if read.wait_readable
rescue Interrupt
end
end
ensure
end
end
run
Updated by byroot (Jean Boussier) about 12 hours ago
Reduced some more, no IO or anything:
def run
fork_safe = ->(t) { t }
RubyVM::YJIT.enable
i = 0
begin
while i < 100
i += 1
p i
begin
next if i
rescue Interrupt
end
end
ensure
end
p :ok
end
run
Updated by ufuk (Ufuk Kayserilioglu) about 11 hours ago
I have a fix for this here: https://github.com/ruby/ruby/pull/16306
Actions