-
Notifications
You must be signed in to change notification settings - Fork 79
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
"IOError: closed stream" when using pipes (JRuby 9k only) #119
Comments
@jordansissel any luck with this / did you bring it up with the JRuby team? I think I might be seeing the same thing. |
Was going through the issue list and found this one intriguing. After some digging, this appears to boil down to a race condition in the example code provided. The error returned is complaining about a closed stream:
If you don't call You can reproduce this issue with MRI Ruby by calling require 'childprocess'
r, w = IO.pipe
proc = ChildProcess.build("echo", "foo")
proc.io.stdout = proc.io.stderr = w
w.close
proc.start
begin
loop { print r.readpartial(8192) }
rescue EOFError
end
proc.wait
The reason the original code doesn't fail on MRI is simply because the process starts and completes execution (and writes all output to the pipe) before The example code can be rewritten so that the pipe is closed after all output is received: require 'childprocess'
r, w = IO.pipe
proc = ChildProcess.build("echo", "foo")
proc.io.stdout = proc.io.stderr = w
proc.start
Thread.new {
begin
loop do
print r.readpartial(8192)
end
rescue EOFError
end
}
proc.wait
w.close The above example works on both MRI and JRuby. |
This issue was originally reported in jordansissel/fpm#1194
I think this problem may be an issue or bug in JRuby specifically, but I wanted to file this here as I walk the dependency chain upwards.
Scenario: I use
IO.pipe
with ChildProcess usually successfully. Recently, someone reported that on JRuby 9k (specifically I tested JRuby 9.1.8.0), the following occurs:I can reproduce this error with the
output to pipe
example:Here's the behavior on a few different rubies:
Ruby 2.4.1
JRuby 1.7.26 (this version is EOL, but presented as more fun data)
JRuby 9.1.8.0
I believe the sample code (and mine) to be correct, and both cause this error in JRuby 9k. I'm not sure if this is a JRuby bug, yet, but will continue digging anyway. Feel free to close if you agree this is a JRuby 9k bug.
The text was updated successfully, but these errors were encountered: