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

Low-level Java error printed on Errno::EPIPE exception #5003

Closed
janko opened this issue Jan 23, 2018 · 7 comments
Closed

Low-level Java error printed on Errno::EPIPE exception #5003

janko opened this issue Jan 23, 2018 · 7 comments

Comments

@janko
Copy link

janko commented Jan 23, 2018

Environment

$ jruby -v
jruby 9.1.15.0 (2.3.3) 2017-12-07 929fde8 Java HotSpot(TM) 64-Bit Server VM 25.40-b25 on 1.8.0_40-b27 +jit [darwin-x86_64]
$ uname -a
Darwin Jankos-MacBook-Pro-2.local 17.3.0 Darwin Kernel Version 17.3.0: Thu Nov  9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64 x86_64

Expected Behavior

When writing to a broken pipe using IO.copy_stream, I expect Errno::EPIPE exception to be raised without anything else printed, as it is the case on MRI:

require "stringio"

read_pipe, write_pipe = IO.pipe
read_pipe.close

IO.copy_stream(StringIO.new("foo"), write_pipe)
script.rb:6:in `write': Broken pipe (Errno::EPIPE)
        from script.rb:6:in `copy_stream'
        from script.rb:6:in `<main>'

Actual Behavior

On JRuby, in addition to the Errno::EPIPE exception, we get a java.io.IOException: Broken pipe internal exception also printed out:

java.io.IOException: Broken pipe
        at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
        at sun.nio.ch.FileDispatcherImpl.write(FileDispatcherImpl.java:60)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
        at sun.nio.ch.IOUtil.write(IOUtil.java:65)
        at sun.nio.ch.SinkChannelImpl.write(SinkChannelImpl.java:167)
        at org.jruby.RubyIO.transfer(RubyIO.java:4323)
        at org.jruby.RubyIO.copy_stream(RubyIO.java:4205)
        at org.jruby.RubyIO$INVOKER$s$0$2$copy_stream.call(RubyIO$INVOKER$s$0$2$copy_stream.gen)
        at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:725)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:208)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:338)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:183)
        at script.invokeOther6:copy_stream(script.rb:6)
        at script.RUBY$script(script.rb:6)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:625)
        at org.jruby.ir.Compiler$1.load(Compiler.java:95)
        at org.jruby.Ruby.runScript(Ruby.java:831)
        at org.jruby.Ruby.runNormally(Ruby.java:750)
        at org.jruby.Ruby.runNormally(Ruby.java:768)
        at org.jruby.Ruby.runFromMain(Ruby.java:581)
        at org.jruby.Main.doRunFromMain(Main.java:417)
        at org.jruby.Main.internalRun(Main.java:305)
        at org.jruby.Main.run(Main.java:232)
        at org.jruby.Main.main(Main.java:204)
Errno::EPIPE: Broken pipe - Broken pipe
  copy_stream at org/jruby/RubyIO.java:4224
       <main> at script.rb:6

Note that the behaviour is still the same, an Errno::EPIPE exception is still raised, but in addition to that java.io.IOException: Broken pipe stack trace is displayed, even when I rescue Errno::EPIPE. The thing is that in my case I'm expecting that Errno::EPIPE will be raised in certain scenarios, so this internal Java stack trace is something that I would prefer wasn't there, because no exception was actually raised.

@enebo enebo added this to the JRuby 9.1.16.0 milestone Jan 23, 2018
enebo added a commit that referenced this issue Jan 23, 2018
@enebo enebo closed this as completed Jan 23, 2018
@enebo
Copy link
Member

enebo commented Jan 23, 2018

HAHAH that should have read 2014. Which was still impressively old but not EPIC

@janko
Copy link
Author

janko commented Jan 23, 2018

@enebo Thank you for such a quick fix!

@janko
Copy link
Author

janko commented Apr 25, 2018

@enebo I'm still seeing the same low-level Java error in JRuby 9.1.17.0 when I execute the script above.

@enebo
Copy link
Member

enebo commented Apr 27, 2018

@janko-m I do not see this:

jruby ../snippets/err3.rb 
Errno::EPIPE: Broken pipe - Broken pipe
        write at org/jruby/RubyIO.java:1431
  copy_stream at org/jruby/RubyIO.java:4697
       (root) at ../snippets/err3.rb:6

Is it possible there is an env like JRUBY_HOME or somehow the older jar is there? Also paste the new stacktrace/ The line numbers will definitely not be exactly the same; so if you see that then it is likely calling an older version still.

@janko
Copy link
Author

janko commented Apr 27, 2018

Hmm, that's strange. Here is the stack trace:

shrine[master, jruby-9.1.17.0]$ ruby script.rb 
java.io.IOException: Broken pipe
        at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
        at sun.nio.ch.FileDispatcherImpl.write(FileDispatcherImpl.java:60)
        at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
        at sun.nio.ch.IOUtil.write(IOUtil.java:65)
        at sun.nio.ch.SinkChannelImpl.write(SinkChannelImpl.java:167)
        at org.jruby.RubyIO.transfer(RubyIO.java:4406)
        at org.jruby.RubyIO.copy_stream(RubyIO.java:4295)
        at org.jruby.RubyIO$INVOKER$s$0$2$copy_stream.call(RubyIO$INVOKER$s$0$2$copy_stream.gen)
        at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:800)
        at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:210)
        at org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:338)
        at org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:183)
        at script.invokeOther6:copy_stream(script.rb:6)
        at script.RUBY$script(script.rb:6)
        at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:625)
        at org.jruby.ir.Compiler$1.load(Compiler.java:94)
        at org.jruby.Ruby.runScript(Ruby.java:830)
        at org.jruby.Ruby.runNormally(Ruby.java:749)
        at org.jruby.Ruby.runNormally(Ruby.java:767)
        at org.jruby.Ruby.runFromMain(Ruby.java:580)
        at org.jruby.Main.doRunFromMain(Main.java:417)
        at org.jruby.Main.internalRun(Main.java:305)
        at org.jruby.Main.run(Main.java:232)
        at org.jruby.Main.main(Main.java:204)
Errno::EPIPE: Broken pipe - Broken pipe
  copy_stream at org/jruby/RubyIO.java:4302
       <main> at script.rb:6

I deleted the previous JRuby version with rm -rf ~/.rbenv/versions/jruby-9.1.15.0, just in case. I don't have $JRUBY_HOME set, and I don't see any Ruby-related env vars that could cause this:

RBENV_SHELL=bash
RBENV_VERSION=jruby-9.1.17.0
RUBY_GC_HEAP_FREE_SLOTS=200000
RUBY_GC_MALLOC_LIMIT=60000000

I actually first noticed the output still being there in the Travis CI build output for shrinerb/shrine, after I had upgraded to jruby-9.1.17.0. I think it'd be strange if both my local and Travis CI were somehow caching an older JRuby version 🤔

@enebo
Copy link
Member

enebo commented Apr 27, 2018

@janko-m oh ffs :| yeah I committed this to our master branch and not out jruby-9.1 branch :( Sorry for a) not actually fixing it in the right place b) making you verify it is actually broken.

@enebo enebo reopened this Apr 27, 2018
@enebo enebo modified the milestones: JRuby 9.1.16.0, JRuby 9.1.18.0 Apr 27, 2018
enebo added a commit that referenced this issue Apr 27, 2018
@enebo enebo closed this as completed Apr 27, 2018
@janko
Copy link
Author

janko commented Apr 27, 2018

No problem, thanks for pushing it out to the jruby-9.1 branch 😃

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

No branches or pull requests

2 participants