def close_io
      [@write_io, @read_io].each do |io|
        begin
          io.close unless io.closed?
        rescue IOError
          raise unless RUBY_ENGINE == 'jruby'
        end
      end
    end
def close_io
      [@write_io, @read_io].each do |io|
        begin
          io.close unless io.closed?
        rescue IOError
          raise unless RUBY_ENGINE == 'jruby'
        end
      end
    end
We grab all the output from PhantomJS like console.log in another thread
 and when PhantomJS crashes we try to restart it. In order to do it we stop
 server and client and on JRuby see this error `IOError: Stream closed`.
 It happens because JRuby tries to close pipe and it is blocked on `eof?`
 or `readpartial` call. The error is raised in the related thread and it's
 not actually main thread but the thread that listens to the output. That's
 why if you put some debug code after `rescue IOError` it won't be shown.
 In fact the main thread will continue working after the error even if we
 don't use `rescue`. The first attempt to fix it was a try not to block on
 IO, but looks like similar issue appers after JRuby upgrade. Perhaps the
 only way to fix it is catching the exception what this method overall does.