Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why did the LocalJumpError cross the road? #2132

Closed
headius opened this issue Nov 6, 2014 · 4 comments
Closed

Why did the LocalJumpError cross the road? #2132

headius opened this issue Nov 6, 2014 · 4 comments

Comments

@headius
Copy link
Member

headius commented Nov 6, 2014

We fixed some MRI test failures recently by changing a "return" to a "break" inside the main server method of WEBrick. The details are here: https://bugs.ruby-lang.org/issues/10478

However, there's a remaining outstanding question: why did the LocalJumpError from this exception bubble out in JRuby and not in MRI? This could be important!

@headius headius added this to the JRuby 9000 milestone Nov 6, 2014
@subbuss
Copy link
Contributor

subbuss commented Nov 7, 2014

All these work .. so, perhaps IR is broken for that webrick method .. could be ensure-related. Doing a quick test now and going to bed. But, that is where one of us should look whoever gets to its first.

[subbu@earth ~/jruby] jruby -e 'Thread.new { return }.join'
LocalJumpError: unexpected return
-e_CLOSURE_1__-e_0 at -e:1
[subbu@earth ~/jruby] jruby -e 'begin; Thread.new { return }.join; rescue; end'
[subbu@earth ~/jruby] jruby -e 'begin; Thread.new { return }.join; rescue StandardError =>e; end'

@subbuss
Copy link
Contributor

subbuss commented Nov 7, 2014

Reproducible on this snippet (jruby 1.7 and jruby 9k both fail on this). The problem is that the ensure executes before the return does (because of ensure-block cloning). However, the return should have ideally executed before the ensure which would have thrown the LJE and would have been caught => control won't get to the ensure before.

But, this highlights a flaw in our ensure handling. However, this is an edge case that only affects LJEs from returns that are caught in code regions that are nested inside other regions with ensures.

Thread.new {
  begin
    begin
      return
    rescue StandardError => e
      p "Error #{e}"
    end
    p 'got out!'
  ensure
    p 'ensured!'
  end
}.join

subbu@earth:/jruby$ jruby -v
jruby 1.7.16.1 (1.9.3p392) 2014-10-28 4e93f31 on Java HotSpot(TM) 64-Bit Server VM 1.7.0_72-b14 +jit [linux-amd64]
subbu@earth:
/jruby$ jruby -X-C /tmp/thr.rb
"ensured!"
LocalJumpError: unexpected return
subbu@earth:/jruby$ rvm use ruby-head
Using /home/subbu/.rvm/gems/ruby-head
subbu@earth:
/jruby$ ruby -v
ruby 2.2.0dev (2014-11-07 trunk 48312) [x86_64-linux]
subbu@earth:~/jruby$ ruby /tmp/thr.rb
"Error unexpected return"
"got out!"
"ensured!"
[subbu@earth ~/jruby] jruby -v
jruby 9.0.0.0.dev-SNAPSHOT (2.2.0p0) 2014-11-07 70cb9a9 Java HotSpot(TM) 64-Bit Server VM 24.72-b04 on 1.7.0_72-b14 +jit [linux-amd64]
[subbu@earth ~/jruby] jruby -X-C /tmp/thr.rb
"ensured!"
LocalJumpError: unexpected return
(root) at /tmp/thr.rb:10

@subbuss
Copy link
Contributor

subbuss commented Nov 7, 2014

I think this would have worked properly in an earlier version of the IR interpreter from 18 odd months back :) .. unverified statement ...

@subbuss
Copy link
Contributor

subbuss commented Nov 11, 2014

Fixed in 9ba99c1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants