Skip to content

Attempt to get output from PTY.spawn periodically hangs #3020

@camlow325

Description

@camlow325

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
end

From the command line, we just run this as jruby ./thefile.rb. We've observed this code fail in multiple ways:

  1. Most often, the process hangs on the cmd_out.getc.chr call.

  2. Sometimes, the process hangs on the Process.wait (pid) call.

  3. Much less frequently - the data that the cmd_out.getc.chr and cmd_out.gets calls 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions