Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.7.0.pre1
-
Fix Version/s: JRuby 1.7.0.pre1
-
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
Fixed by master@00d30e1.
commit 00d30e159ba2cbbe01c04d4fd2b8bd46d9b2ee6a Author: Charles Oliver Nutter <headius@headius.com> Date: Tue Dec 20 18:00:38 2011 -0600 Fix JRUBY-6291: Closing One Stream From IO.popen4 Results in Stream Closed Error When Reading Other Streams Ben figured this one out. The logic I put in place to ensure the child process gets nuked for a popen stream was causing it to be nuked prematurely for popen3/4 streams. I added a "popenSpecial" boolean to RubyIO, so we know not to do that.