-
-
Notifications
You must be signed in to change notification settings - Fork 942
Description
We're experiencing periodic hangs during attempts to read the output from or wait on a process created by a call to PTY.spawn. Here's a snippet of code which demonstrates the problem:
require 'pty'
itr = 0
while true
itr = itr + 1
puts "iteration - #{itr}"
PTY.spawn('/bin/echo blah') do |cmd_out, cmd_in, pid|
begin
puts "pid - #{pid}"
one_char = cmd_out.getc.chr
puts "first char - #{one_char}"
rest = cmd_out.gets
puts "rest chars - #{rest}"
ensure
puts "closing cmd_out..."
cmd_out.close
puts "closing cmd_in..."
cmd_in.close
puts "wait for #{pid}"
Process.wait(pid)
puts "done waiting for #{pid}"
end
end
endFrom the command line, we just run this as jruby ./thefile.rb. We've observed this code fail in multiple ways:
-
Most often, the process hangs on the
cmd_out.getc.chrcall. -
Sometimes, the process hangs on the
Process.wait (pid)call. -
Much less frequently - the data that the
cmd_out.getc.chrandcmd_out.getscalls read back appears to be the path to the jruby jar + an error message. For example:
first char = /
rest chars = .../jruby-1.7.20/lib/jruby.jar: invalid LOC header (bad signature)
It is pretty uncommon to get through more than about about 150 iterations or so before one of the failures above happens. The third failure, when it occurs, is usually on the first PTY.spawn call.
I've been able to reproduce this failure on multiple versions of JRuby - including 1.7.19, 1.7.20, 9.0.0.0.pre2. I haven't seen the program run indefinitely without failing on any version of JRuby, so I suspect that this may never have worked.
Is there something obviously wrong about the way we're using PTY.spawn here, or is PTY.spawn basically not functional at this point?