Skip to content

Instantly share code, notes, and snippets.

@bts
Created May 31, 2013 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bts/5686936 to your computer and use it in GitHub Desktop.
Save bts/5686936 to your computer and use it in GitHub Desktop.
Intermittent IO.popen "Bad file descriptor" failures upon IO#close when using read+write mode on JRuby 1.7.3.
% jruby -J-Djruby.backtrace.style=raw popen.rb
using r...
using r+...
IOError: Bad file descriptor
getStackTrace at java/lang/Thread.java:1567
getBacktraceData at org/jruby/runtime/backtrace/TraceType.java:171
getBacktrace at org/jruby/runtime/backtrace/TraceType.java:39
prepareBacktrace at org/jruby/RubyException.java:215
preRaise at org/jruby/exceptions/RaiseException.java:214
preRaise at org/jruby/exceptions/RaiseException.java:195
<init> at org/jruby/exceptions/RaiseException.java:112
newRaiseException at org/jruby/Ruby.java:3654
newIOErrorFromException at org/jruby/Ruby.java:3585
finalize at org/jruby/util/io/OpenFile.java:399
cleanup at org/jruby/util/io/OpenFile.java:318
close2 at org/jruby/RubyIO.java:2074
close at org/jruby/RubyIO.java:2052
call at org/jruby/runtime/callsite/CachingCallSite.java:134
ls at popen.rb:5
ls at popen.rb:5
call at org/jruby/runtime/callsite/CachingCallSite.java:168
(root) at popen.rb:12
(root) at popen.rb:12
yield at org/jruby/runtime/CompiledBlock19.java:139
yield at org/jruby/runtime/Block.java:130
times at org/jruby/RubyFixnum.java:273
cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:316
callBlock at org/jruby/runtime/callsite/CachingCallSite.java:145
callIter at org/jruby/runtime/callsite/CachingCallSite.java:154
(root) at popen.rb:12
(root) at popen.rb:12
runScript at org/jruby/Ruby.java:815
runScript at org/jruby/Ruby.java:808
runNormally at org/jruby/Ruby.java:679
runFromMain at org/jruby/Ruby.java:528
doRunFromMain at org/jruby/Main.java:390
internalRun at org/jruby/Main.java:279
run at org/jruby/Main.java:221
main at org/jruby/Main.java:201
#!/usr/bin/env jruby
def ls(mode)
io = IO.popen('ls', mode)
io.close
end
puts "using r..."
800.times { ls('r') } # always succeeds
puts "using r+..."
800.times { ls('r+') } # usually fails
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment