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

Java exceptions do not propagate out of Thread#join #2354

Closed
headius opened this issue Dec 29, 2014 · 4 comments
Closed

Java exceptions do not propagate out of Thread#join #2354

headius opened this issue Dec 29, 2014 · 4 comments

Comments

@headius
Copy link
Member

headius commented Dec 29, 2014

From http://jira.codehaus.org/browse/JRUBY-7129

Joining a thread that died from a normal Ruby error will kill the parent thread, as expected. The "should not be here" text is never printed:

$ jruby -e "Thread.new{raise 'error'}.join; puts 'should not be here'"
RuntimeError: error
  (root) at -e:1

However, if the thread died from a raw Java error, joining the thread only prints a trace, and the "should not be here" text is printed.

rcrogers@proc1-ss1.dev:~/statsheet$ jruby -e "Thread.new{a = []; loop{a << 'word'}}.join; puts 'should not be here'"
Exception in thread "RubyThread-1: -e:1" java.lang.OutOfMemoryError: Java heap space
    at org.jruby.RubyString.newStringShared(RubyString.java:571)
    [...]
    at org.jruby.internal.runtime.RubyRunnable.run(RubyRunnable.java:98)
    at java.lang.Thread.run(Thread.java:679)
should not be here

Still fails on 1.7 and 9k heads.

@headius
Copy link
Member Author

headius commented Dec 29, 2014

This logic is pretty messy and needs a rework. Here is a partial, not-compiling attempt at a patch that may be along the right lines for fixing this bug: https://gist.github.com/headius/e87a4723d643cfd38769

@rtyler
Copy link

rtyler commented Mar 23, 2015

I'm pretty sure I've experienced this behavior when working with native Java libraries, going to see if I can convince @mkristian to fix it :D

ABaldwinHunter pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Sep 29, 2016
This fixes an issue where java execptions did not propogate up in Thread#join.

See related issue for more information: jruby/jruby#2354
ABaldwinHunter pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Sep 29, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
ABaldwinHunter pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Sep 29, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
ABaldwinHunter pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Sep 29, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
maxjacobson pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Oct 5, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
maxjacobson pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Oct 5, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
maxjacobson pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Oct 10, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
maxjacobson pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Oct 10, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
maxjacobson pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Oct 10, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
maxjacobson pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Oct 24, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
maxjacobson pushed a commit to codeclimate/codeclimate-duplication that referenced this issue Oct 24, 2016
Fixes an issue where Java exceptions did not propogate up in Thread#join and
could result in issues getting dropped.

See related issue for more information: jruby/jruby#2354
@andreaseger
Copy link

Any update on this? I can still see this happening and causing weird issues

@headius
Copy link
Member Author

headius commented Apr 11, 2018

This turned out to be easier to fix than it used to be, so I went ahead with it. Java exceptions that bubble out of Ruby threads will now behave like Ruby threads as regards Thread#join, Thread#value, and other exception-aware methods of Thread.

@headius headius closed this as completed Apr 11, 2018
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

4 participants