Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.6
-
Fix Version/s: JRuby 1.6.7
-
Component/s: None
-
Labels:None
-
Environment:Java 6
-
Number of attachments :
Description
The small snippet below results in an IOError: Stream closed on the stdout_io.each_line line. Removing the stdin.close gets rid of the error.
IO.popen4("ls") do |pid, stdin, stdout, stderr| stdin.close [ Thread.new(stdout) {|stdout_io| stdout_io.each_line do |l| STDOUT.puts l STDOUT.flush end stdout_io.close }, Thread.new(stderr) {|stderr_io| stderr_io.each_line do |l| STDERR.puts l STDERR.flush end } ].each( &:join ) end
RubyIO's close2 method has code to destroy any spawned processes associated with an IO object that gets closed. So, the workaround is to not close any of the IO streams until the process has finished or the program has finished consuming the process output. See:
https://github.com/jruby/jruby/blob/master/src/org/jruby/RubyIO.java#L3810
https://github.com/jruby/jruby/blob/master/src/org/jruby/RubyIO.java#L2002
Cloned from
JRUBY-6291- this issue was present in 1.7 and fixed by the commit https://github.com/jruby/jruby/commit/00d30e159ba2cbbe01c04d4fd2b8bd46d9b2ee6a with test in commit https://github.com/jruby/jruby/commit/70d42fb23b34c021cc18a2980ba65422bd9c4692I don't know for sure if it's the same underlying issue, but the example code above does exhibit the same problem under 1.6.6