Basically, it appears that if you open a pipe, then the main thread exits, other threads still running "stop begin able to write to that pipe" (my assumption is it was closed when the main thread exited). I think I've run into this before, but couldn't find a ticket for it easily, so sorry if it's a dupe. It seems to reproduce at least in windows 7 with jdk 1.6 and windows xp with jdk 7.
This snippet should output 'hello'
a = IO.popen("jruby -e 'puts gets'", "w")
sleep 1 # let it start
timer = javax.swing.Timer.new(1000, nil)
timer.repeats=false # may not be necessary
# allow main thread to exit -- uncomment the sleep line and it works as expected.
as is, it responds with
Exception in thread "AWT-EventQueue-0" org.jruby.exceptions.RaiseException: (Errno::EBADF) Bad file descriptor
or within a larger program:
Errno::EBADF: Bad file descriptor - Bad file descriptor
read at org/jruby/RubyIO.java:2904
` at file:/C:/installs/jruby-1.7.0/lib/jruby.jar!/jruby/kernel/jruby/process_manager.rb:35
` at file:/C:/installs/jruby-1.7.0/lib/jruby.jar!/jruby/kernel/jruby/process_manager.rb:49
set_all_ffmpegs_as_lowest_prio at C:/dev/dirt-simple-usb-surveillance/./lib/go.rb:17
do_something at C:/dev/dirt-simple-usb-surveillance/./lib/go
IOError: Stream closed
The difficult thing with this is that the errors sometimes can manifest themselves "unreliably" because it depends if the main thread has exited yet or not. In my case, sometimes it has, sometimes it hasn't, which makes this a frustrating bug to trace.
The text was updated successfully, but these errors were encountered:
This is unlikely to be fixed now or ever; we'd need to know that one of the many JVM threads is a user thread still active in the system and still dependent on the streams we shut down on exit. The lifecycle of the JRuby instance is only as long as the lifecycle of "main" when running from the command line. If you want to keep it valid longer than that, wait for those threads to shut down in your main thread or block the main thread until it's safe to exit. Treat script exit like app exit.