Skip to content

Break in block passed to Thread doesn't cause LocalJumpError #7009

@toy

Description

@toy

Following code doesn't cause a LocalJumpError in JRuby unlike in MRI:

proc do |&block|
  Thread.new{ block.call }.join
end.call{ break }

Using docker to compare behaviour:

cat << 'RUBY' > test.rb
puts '#' * 60, "Using #{RUBY_DESCRIPTION}"
$stdout.flush

proc do |&block|
  Thread.new{ block.call }.join
end.call{ break }

puts "Still alive!"
RUBY

cat test.rb | docker run -i --rm ruby:2.7 ruby
cat test.rb | docker run -i --rm ruby:3.0 ruby
cat test.rb | docker run -i --rm ruby:3.1 ruby
cat test.rb | docker run -i --rm jruby:9.2 jruby
cat test.rb | docker run -i --rm jruby:9.3 jruby

Gives following output:

############################################################
Using ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
#<Thread:0x000055eb7e475698 -:5 run> terminated with exception (report_on_exception is true):
-:6:in `block in <main>': break from proc-closure (LocalJumpError)
	from -:5:in `block (2 levels) in <main>'
-:6:in `block in <main>': break from proc-closure (LocalJumpError)
	from -:5:in `block (2 levels) in <main>'
############################################################
Using ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
#<Thread:0x00005632073b3668 -:5 run> terminated with exception (report_on_exception is true):
-:6:in `block in <main>': break from proc-closure (LocalJumpError)
	from -:5:in `block (2 levels) in <main>'
-:6:in `block in <main>': break from proc-closure (LocalJumpError)
	from -:5:in `block (2 levels) in <main>'
############################################################
Using ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-linux]
#<Thread:0x00007f5f06b234e8 -:5 run> terminated with exception (report_on_exception is true):
-:6:in `block in <main>': break from proc-closure (LocalJumpError)
	from -:5:in `block (2 levels) in <main>'
-:6:in `block in <main>': break from proc-closure (LocalJumpError)
	from -:5:in `block (2 levels) in <main>'
############################################################
Using jruby 9.2.20.1 (2.5.8) 2021-11-30 2a2962fbd1 OpenJDK 64-Bit Server VM 25.312-b07 on 1.8.0_312-b07 +jit [linux-x86_64]
Exception in thread "Ruby-0-Thread-1: -:1" org.jruby.ir.runtime.IRBreakJump
Still alive!
############################################################
Using jruby 9.3.2.0 (2.6.8) 2021-12-01 0b8223f905 OpenJDK 64-Bit Server VM 25.312-b07 on 1.8.0_312-b07 +jit [linux-x86_64]
Exception in thread "Ruby-0-Thread-1: -:1" org.jruby.ir.runtime.IRBreakJump
Still alive!

Related to #4686 and #4697

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions