Skip to content
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

read is blocked after select in IO.popen3 #5765

Open
yamam opened this issue Jun 13, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@yamam
Copy link

commented Jun 13, 2019

Read of IO.popen3 output does not end, even if select tells you can read.

Environment

jruby 9.1.17.0 (2.3.3) 2019-02-26 fffffff OpenJDK 64-Bit Server VM 11.0.3+7-Ubuntu-1ubuntu218.04.1 on 11.0.3+7-Ubuntu-1ubuntu218.04.1 +jit [linux-x86_64]

Expected Behavior

input, output, err, pid = IO.popen3("sh -c 'echo aaa;sleep 10'")
while true
    puts "select start"
    reads, = IO.select([output])
    puts "select end"
    if reads.include?(output)
        if l = output.readpartial(10000)
            p l
        else
            exit
        end
    end
end

This script will output the following.
'select' ends after 10 seconds.

select start
select end
"aaa\n"
select start
(after 10 seconds)
select end
EOFError: End of file reached

Actual Behavior

'select' will be over soon, but read is blocked.

select start
select end
"aaa\n"
select start
select end
(after 10 seconds)
EOFError: End of file reached
@yamam

This comment has been minimized.

Copy link
Author

commented Jun 13, 2019

In Linux jruby 9.2.8.0 this problem did not occur in Open3.popen 3, but in IO.popen 3. However, on Windows, this happens in both IO.popen3 and Open3.popen3.

The following is a test script for Windows.

input, output, err, pid = IO.popen3("echo aaa & powershell sleep 10")
while true
    puts "select start"
    reads, = IO.select([output])
    puts "select end"
    if reads.include?(output)
        if l = output.readpartial(10000)
            p l
        else
            exit
        end
    end
end

jruby -v
jruby 9.2.8.0-SNAPSHOT (2.5.3) 2019-06-13 49e54c1 Java HotSpot(TM) Client VM 25.201-b09 on 1.8.0_201-b09 +jit [mswin32-i386]

jruby test.rb
select start
select end
"aaa \r\n"
select start
select end
(after 10 seconds)
EOFError: End of file reached

@headius headius added the windows label Jun 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.